0

我被要求将多个附件(最多 5 个)保存到数据库中,然后将它们检索到 php.ini 中的另一个页面。我已经为此搜索了一周以上,并且只找到可以将一个文件保存到数据库然后检索它们的教程。

我的情况是我正在发送带有多个附件的电子邮件,电子邮件保存在“电子邮件”表中,现在我希望附件也保存在那里,在另一列中,因此很容易在 php 页面上检索它们.

在这种情况下,请任何人帮助我。给我一个正确的指导方针。我正在使用 phpmyadmin 来保存所有所说的内容

4

1 回答 1

1

这是您想要的解决方案:将 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);

由于您有文件 int 内存并且它们是 base64 编码的,因此您可以使用Content-Transfer-Encoding: base64.

于 2012-04-10T20:19:48.440 回答