如何在MySQL数据库中存储PDF文件? [英] How to store a PDF file in MySQL database?
本文介绍了如何在MySQL数据库中存储PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用PHP将PDF文件存储在MySQL数据库中?
How to store a PDF file in a MySQL database using PHP?
推荐答案
使用BLOB(二进制大对象)(longblob
数据类型)
Using BLOB (Binary Large Object) (longblob
datatype)
$fileHandle = fopen($fileUpload, "r");
$fileContent = fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);
$dbQuery = "INSERT INTO myBlobs VALUES ";
$dbQuery .= "('$fileContent')";
完整教程可在此处
,但强烈建议将文件存储在文件系统上,只需在数据库中添加引用(带有文件路径和名称的字段).几个原因:
but it's strongly recommended to store files on the file system, and just add a reference in the DB (a field with the file path and name). Several reasons:
- 更快
- 易于访问(不需要任何特殊应用)
- 快速备份
- 更少的空间
这篇关于如何在MySQL数据库中存储PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文