本文介绍了大.PDF文件未上传到MySQL数据库中的BLOB通过PHP,文件下2MB做工精细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个PHP脚本上传.pdf文档为介质的BLOB成通过PHP MySQL数据库。该脚本还允许用户搜索文件和开/下载它们,但我不觉得剧本的那部分是有关我的问题。当我尝试上传的文件超过2 MB没有什么会成为我的内容(中BLOB)列,并有MIME类型没有价值的脚本正常工作与文件小于2 MB,但一旦。我已经尝试从1 MB的默认值增加MAX_PACKET_SIZE为MySQL服务器4 MB。我也更新php.ini中正确的价值观,我想。我设置upload_max_size为4MB,post_max_size要到4 MB,和memory_limit的16 MB。我还没有真正与max_input_time设置实验,但因为它是默认为60秒这似乎是很多考虑这个脚本是在Intranet内部应用程序。

I am developing a PHP script for uploading .PDF documents as medium BLOBs into a MySQL database via PHP. The script also allows users to search for files and open/download them but I do not think that part of the script is relevant to my issue. The script works fine with files less than 2 MB but as soon as I try and upload a file that is more than 2 MB nothing is going into my content(Medium BLOB) column and there is no value for the mime type. I have already tried increasing the max_packet_size for the MySQL server to 4 MB from its default value of 1 MB. I have also updated php.ini to the correct values, I think. I set upload_max_size to 4MB, post_max_size to 4 MB, and memory_limit to 16 MB. I haven't really experimented with the max_input_time though because it is defaulted to 60 seconds which seems like plenty considering this script is for an internal application on an intranet.

我也试图赶在我和errorInfo中脚本从PDO对象错误()和错误code(),并通过双方0(没有错误)。

I have also tried to catch errors from the PDO object in my script with errorInfo() and errorCode() and both through 0s (no error).

下面是我的脚本上传部分:

Here is the upload section of my script:

if ($key == 'upload')
{
	set_time_limit(0);
	$_SESSION['upload'] = $value;

	if ($_FILES['userfile']['name'])
	{
		$fileName = $_FILES['userfile']['name'];
		$tmpName  = $_FILES['userfile']['tmp_name'];
		$fileSize = $_FILES['userfile']['size'];
		$fileType = $_FILES['userfile']['type'];
		$docType = $_POST['docType'];
		$netKey = $_POST['netKey'];
		$fp       = fopen($tmpName, 'r');
		$content  = fread($fp, filesize($tmpName));
		$content  = addslashes($content);
        fclose($fp);

        $_SESSION['filetype'] = $fileType;

		if(!get_magic_quotes_gpc())
		{
    		$fileName = addslashes($fileName);
		}
		$sqlCheck = "SELECT id, name, documentType, networkKey FROM upload WHERE active='1'";
		foreach ($dbh->query($sqlCheck) as $row)
		{
			if (($row['name'] == $fileName) && ($row[networkKey] == $netKey) && ($row['documentType'] == $docType)) 
			{
				$_SESSION['updateRow'] = $row['id'];
			}

		}

		if ($_SESSION['updateRow'])
			{
				$deactivateDuplicate = "UPDATE upload SET active = 0, modifiedBy = '".strtoupper($_SERVER['REMOTE_USER'])."', modifiedDate = Now() WHERE id = '".$_SESSION['updateRow']."' AND active ='1'";
				$dbh->query($deactivateDuplicate);
				$_SESSION['sql'] = "SELECT id, name, documentType, type, size, networkKey, modifiedBy, modifiedDate, active FROM upload WHERE active = '1'";
				$_SESSION['uploadSearch'] =	1;
				$_SESSION['updateRow'] = 0;
			}
			$values = "'".$fileName."','".$docType."','".$fileType."','".$content."','".$fileSize."','".$netKey."','".strtoupper($_SERVER['REMOTE_USER'])."', Now(), 1";
			$sqlUpload = "INSERT INTO upload (name, documentType, type, content, size, networkKey, modifiedBy, modifiedDate, active) VALUES (".$values.")";
			$dbh->query($sqlUpload);

			$_SESSION['sql'] = "SELECT id, name, documentType, type, size, networkKey, modifiedBy, modifiedDate, active FROM upload WHERE active = '1'";
			$_SESSION['uploadSearch'] =	1;


	}
}

和这里是应用程序的前端表示一个更小的文件的作品和较大的文件不。该文件sample.pdf小于1 MB,并且文件检验.pdf是2.5 MB。

And Here is the front end of the application showing that a smaller file works and a larger file does not. The file sample.pdf is less than 1 MB and the file test.pdf is 2.5 MB.

我会用的img标签,但可惜我是一个新用户,并不允许的。

I would have used img tags but alas I am a new user and not allowed.

我要寻找的下一件事就是在Apache的那会将文件大小限制的设置。我是新来的主灯,任何提示将是巨大的。
谢谢

The next thing I am going to look for is a setting in Apache that limits file sizes. I am new to LAMP so any tips would be great.Thanks

推荐答案

其实我固定的问题。我改变了所有在这里建议在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.

这篇关于大.PDF文件未上传到MySQL数据库中的BLOB通过PHP,文件下2MB做工精细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 09:39