-
12-12-2019 - |
题
我需要将上传的文件保存到数据库中,最好保存在表 core_file_storage 中作为 blob 并稍后检索。我希望将其与客户联系起来。目前,文件正在保存在文件系统中,需要停止。
解决了:我使用 model mage/core/file/Model/storage/database.php 方法写入表 core_file_storage
解决方案
不确定为什么您停止将文件存储在文件系统中,不建议存储在数据库中,因为您的数据库会很快变得巨大。
表架构是什么?您可以通过使用获取文件内容来保存 blob 文件 file_get_contents
PHP 函数。
将以下内容替换为您的真实数据后,尝试这样的操作:
Mage::getModel('core/file_storage')
->setCustomerId($custId)
->setYourFile(file_get_contents('/path/to/file.ext'))
->save();
然后获取:
Mage::getModel('core/file_storage')->load($custId);
$blobFile = $cust->getYourFile();
//并显示在前端...如果是图像:
header("Content-type: image/jpg"); //Send the content Type here.
echo $blobFile;