通过PHP脚本,文件上载仅限于RHEL 6.4中的1MB

时间:2013-12-20 06:19:52

标签: php apache

我已将php.ini文件中的配置更改为:

upload_max_size=100MB;
file_uploads is also ON;

但是以下代码在Windows本地服务器XAMPP上运行正常。相同的脚本允许将任何文件大小上载到数据库。在Linux中仅限于1 MB。

我还检查了my.cnf文件,但没有选项允许在Windows my.ini文件中提供最大数据包大小。

// This is the temporary place where it got put on the server
// after it was uploaded
$tempfile = $_FILES["uploadedfile$i"]["tmp_name"] ;

// addslashes so as not to break anything :)
if(!empty($tempfile)){
    //$data = addslashes(fread(fopen($tempfile, "rb"), filesize($tempfile)));
    $data = addslashes(fread(fopen($tempfile, "rb"),filesize($tempfile)));
    $fp = fopen($_FILES["uploadedfile$i"]['tmp_name'], 'rb');
}
// pull out useful bits in case they are needed. 
$filetype = $_FILES["uploadedfile$i"]["type"];
$filesize = $_FILES["uploadedfile$i"]["size"];
$filename = $_FILES["uploadedfile$i"]["name"];

这是将文件上传到数据库的命令:

$query=$this->db->prepare("insert into $table 
  (filename,data,filexml,filesize,filetype,filetype1,category,filesize1)
  values (?,?,?,?,?,?,?,?)");  
$query->bindValue(1,$filename,PDO::PARAM_STR);
$query->bindParam(2,$fp,PDO::PARAM_LOB);
$query->bindValue(3,$filexml,PDO::PARAM_STR);
$query->bindValue(4,$filesize,PDO::PARAM_STR);
$query->bindValue(5,$filetype,PDO::PARAM_STR);
$query->bindValue(6,$filetype1,PDO::PARAM_STR);
$query->bindValue(7,$_SESSION['radbut'],PDO::PARAM_STR); 
$query->bindValue(8,$filesize1,PDO::PARAM_INT);
$query->execute();   
echo $table;    
echo 'wav eee upload successful';

1 个答案:

答案 0 :(得分:0)

我们没有足够的有关您的配置的信息来完全帮助您,但以下是您可以遵循的一些线索:

  • 检查post_max_size文件的php.ini
  • 同时检查您在php.ini中设置的参数是否已成功设置到phpinfo()中(确保它未被Apache覆盖)
  • 如果您安装了suhosin,请检查其参数,有时可能会很棘手
  • 检查Apache日志以查找有关错误的更多信息(以及suhosin错误的系统日志信息)
  • 您要插入的文件大小和数据库字段的大小是什么?
  • 正如Mike指出的那样,检查max_allowed_packet MySQL配置上的my.cnf
  • 确保在更改了这些参数后重新启动了MySQL和Apache。

正如迈克所指出的,MySQL不是为存储大文件而设计的。

如果您确实需要将其存储到数据库中,请考虑使用具有MongoDB功能的NoSQL数据库,例如GridFS