BLOB下载被截断为1 MB的脚本作品小于1 MB的文件 [英] BLOB Download Truncated at 1 MB Script Works for Files Less Than 1 MB
问题描述
我最近才问并解决了一个有关将大于2 MB的.PDF文件作为BLOBS上载到MySQL数据库的问题.我必须更改php.ini文件中的某些设置以及MySQL的最大数据包设置.但是,解决此问题使我发现我的脚本有一个新问题.
I just recently asked and solved a question pertaining to uploading .PDF files that are greater than 2 MB into a MySQL database as BLOBS. I had to change some settings in my php.ini file and MySQLs maximum packet setting. However, fixing this issue has led me to discover a new issue with my script.
现在,由于我可以将文件上传到我的BLOB数据库中,因此我尝试下载该文件以进行测试.当我打开.PDF文件时,令我非常沮丧的是,我收到以下错误:无法加载文档(错误3)"file:///tmp/test-13.pdf".经过进一步调查,我发现正在下载的文件test.pdf仅为1 MB,略小于数据库中假定大小的一半(略大于2 MB).这显然是错误的原因.
Now since I can upload files to my BLOB database I attempted to download the file for testing purposes. Much to my dismay when I went to open the .PDF file I received the following error: Failed to load document (error 3) 'file:///tmp/test-13.pdf'. Upon further investigation I found out that the file being downloaded, test.pdf, was only 1 MB, a little less than half of its supposed size in the database of a little more than 2 MB. This is obviously the reason for the error.
以下代码是我用来从数据库下载文件的脚本的一部分.它位于脚本的最顶端,对于小于1 MB的文件,可以正常工作.
The following piece of code is the part of my script I am using for downloading files from the database. It is is at the very top of of script and works Flawlessly for files that are less than 1 MB.
foreach($_REQUEST as $key => $value)
{
if ($value == 'Open')
{
header();
session_start();
$dbh = new PDO('mysql:host='.$_SESSION['OpsDBServer'].'.ops.tns.its.psu.edu;
dbname='.$_SESSION['OpsDB'], $_SESSION['yoM'], $_SESSION['aMa']);
$id = $key;
$sqlDownload = "SELECT name, type, content, size FROM upload WHERE
id='".$id."'";
$result = $dbh->query($sqlDownload);
$download = $result->fetchAll();
$type = $download[0]['type'];
$size = $download[0]['size'];
$name = $download[0]['name'];
$content = $download[0]['content'];
header("Content-type: $type");
header("Content-Disposition: inline; filename=$name");
header("Content-length: $size");
header("Cache-Control: maxage=1");
header("Pragma: public");
echo $content;
exit;
}
}
我在想,也许我的一些标题语句错了吗?我对要做的事很困惑.我搜索了php.ini,没有发现我认为需要更改的设置,而MySQL的最大数据包设置为4 MB,因此应下载2 MB.
I am thinking that maybe I have some header statements wrong? I am very confused about what to do. I have searched through php.ini and I have found no settings that I think need to changed and my maximum packet setting for MySQL is 4 MB so a 2 MB should download.
感谢您的帮助.
推荐答案
我实际上已解决了该问题.我更改了php.ini和my.cnf中建议的所有值,但我还需要更改PDO的设置.
I actually fixed the issue. I changed all of the values that were recommended here in php.ini and my.cnf but I also needed to change a setting for PDO.
我更改了: PDO :: MYSQL_ATTR_MAX_BUFFER_SIZE(整数) 最大缓冲区大小.默认为1 MiB.
I changed: PDO::MYSQL_ATTR_MAX_BUFFER_SIZE (integer) Maximum buffer size. Defaults to 1 MiB.
必须在创建PDO对象时设置此项.现在一切都很好.
This has to be set when the PDO object is created to work though. All is good now.
这篇关于BLOB下载被截断为1 MB的脚本作品小于1 MB的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!