PHP:将Pdf上载到SQL数据库 [英] PHP: Upload a Pdf to SQL Database

查看:181
本文介绍了PHP:将Pdf上载到SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想知道从pdf上载到sql数据库的起点.我正在尝试使用户可以上载文件,然后单击提交",并且该文件存储在sql数据库的单元格中.这是解决此问题的正确方法吗?我根本不需要解析pdf,我只需要能够将其上传并从数据库中拉回即可.谢谢!

Hi so I am wondering where to start on uploading a pdf to a sql database. I am trying to make it so that a user can upload a file and then hit submit and that file is stored in a cell on a sql database. Is this the correct way to solve this problem? I do not need to parse the pdf at all, I just need to be able to upload it and pull it back out of the database. Thank you!

推荐答案

如果您真的想将pdf(作为BLOB)存储在数据库中,(假设正在使用MySQL函数与数据库进行接口),您可以执行以下操作这个:

If you really want to store pdf (as BLOB) in the database, (Assuming MySQL functions are being used to interface with the database) You could do something like this:

$store_pdf =  mysql_query("INSERT INTO table (data) VALUES ('".mysql_real_escape_string(file_get_contents('/pdf/file/path.pdf'))."')");

注意:

通常不考虑在数据库中存储BLOB.更好的方法是将文件移动到文件系统中的某个位置,并将该文件的路径而不是文件本身存储在数据库中.

Storing BLOBs in databases is generally not considered. A better approach would be to move the file somewhere in the filesystem and store the path to the file in the database instead of the file itself.

例如.

$path_to_pdf='/pdf/file/path.pdf';

mysql_query("INSERT INTO table (pdf_path) VALUES ('$path_to_pdf')");

&从表中获取路径后,访问pdf文件.

& Access pdf file after fetching the path from the table.

<?php 
$query=mysql_query("SELECT pdf_path FROM table");
$result=mysql_fetch_array($query);
?>
<a href="<?php echo $result['pdf_path']; ?>">Download PDF</a>

请注意,现在已不建议使用mysql扩展,以后将在某个时候将其删除.您可以改为使用PDO函数. ( http://www.php.net/manual/zh/book.pdo. php )

Note that the mysql extension is now deprecated and will be removed sometime in the future. You could use PDO functions instead. (http://www.php.net/manual/en/book.pdo.php)

这篇关于PHP:将Pdf上载到SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆