我被要求将多个附件(最多5个)保存到数据库中,然后在php中将它们检索到另一个页面。我已经用谷歌搜索了一周以上,发现只有教程可以保存一个文件到数据库,然后检索它们。
我的场景是我正在发送一封带有这些多个附件的电子邮件,电子邮件被保存在一个表" Email“中,现在我希望附件也被保存在那里,在另一列中,所以很容易在一个php页面上检索它们。
在这种情况下,请任何人帮助我。给我提供一个合适的指南。我使用phpmyadmin保存上述所有内容。
发布于 2012-04-11 04:19:48
这是你想要的解决方案:一旦你上传了5个文件到服务器,将它们读入内存和base64_encode。
例如。
$files = array(
'file1' => base64_encode(file_get_contents('/path/to/file1')),
'file2' => base64_encode(file_get_contents('/path/to/file2')),
'file3' => base64_encode(file_get_contents('/path/to/file3')),
'file4' => base64_encode(file_get_contents('/path/to/file4')),
'file5' => base64_encode(file_get_contents('/path/to/file5')),
);
// serialize
$filesData = serialize($files);
// put $filesData in db column
// when your retrieve it later from database, unserialize and use array
$files = unserialize($columnValue);由于您有内存中的文件,并且它们是base64编码的,因此可以使用Content-Transfer-Encoding: base64添加附件。
https://stackoverflow.com/questions/10090148
复制相似问题