PHP上传文件错误代码3 [英] php upload file error code 3

查看:1060
本文介绍了PHP上传文件错误代码3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上传大文件(> 10KB)将在$ _FILES ['file'] ['error'] 错误代码3(UPLOAD_ERR_PARTIAL) >和小文件(<10KB)将成功上传。



如果文件超过限制php post_max_size upload_max_filesize ,它应该得到错误代码1 UPLOAD_ERR_INI_SIZE 。但是,获取错误代码3 UPLOAD_ERR_PARTIAL 不正确

使用下面的软件及其版本



使用下面的软件及其版本


$ b


  1. php 5.6.17
  2. apache 2.4.18

以下是 php.ini

  post_max_size = 8M 
file_uploads = On
upload_tmp_dir =/ tmp
upload_max_filesize = 2M

当上传大文件(hi.png)时,错误日志记录在/var/log/httpd-error.log中

  PHP注意:在文件hi.png的数据末尾缺少行0中未知的

这里是index.php

 <!DOCTYPE html> 
< html>
< body>
< form action ='upload.php'method ='post'enctype ='multipart / form-data'>
选择要上传的图片:
< input type ='file'name ='fileToUpload'id ='fileToUpload'>
< input type ='submit'value ='上传图片'name ='submit'>
< / form>
< / body>
< / html>

和upload.php

<$ p $ ($ _ FILES ['fileToUpload'] ['error']> 0){
echoerror code。$ _ FILES ['fileToUpload '] [' 错误'] <峰; br> 中。
}
else {
echofile name:。$ _ FILES ['fileToUpload'] ['name']。< br>;
echofile type:。$ _ FILES ['fileToUpload'] ['type']。< br>;
echofile size:。$ _ FILES ['fileToUpload'] ['size']。< br>;
echofile path:。$ _ FILES ['fileToUpload'] ['tmp_name']。< br>;
$ b $ move_uploaded_file($ _ FILES ['fileToUpload'] ['tmp_name'],uploads /\".$_ FILES ['fileToUpload'] ['name']);
}
?>


解决方案

php 5.6.18和apache 2.4.18:超过7950字节的文件将不断地和一贯地失败,错误3,无论设置了哪些限制。



问题:PHP模块(mod_php56)是使用apache2filter SAPI编译的,但通过AddHandler作为处理程序启用。解决方案是检查端口选项,并使用标准选项(不包括AP2FILTER)重新构建mod_php56
$ b 长篇小说:检查是否有端口选项 OPTIONS_FILE_SET + = AP2FILTER (Apache 2过滤SAPI),但PHP配置了通常的处理方式( AddType application / x-httpd-php .php )。删除选项(作为默认的构建/端口),并重建mod_php56包解决了我的问题。为了验证是否也是这种情况,可以使用 php_sapi_name()来回显。如果它是 apache2filter ,但是通过 AddHandler 指令启用了php,你有同样的问题。重建后,您的php_sapi_name()应该是 apache2handler 。这两个选项都可以在 phpinfo()中分别作为Apache 2.0 Filter和Apache 2.0 Handler进行检查。
$ b

请注意,这并不能解释为什么它实际上破坏了上传(或者为什么模块首先使用Handler配置)。
您也可以通过将mod_php作为过滤器而不是作为处理程序来成功,但是我没有在这里检查。


Upload bigger file( > 10KB) will get error code 3(UPLOAD_ERR_PARTIAL) in $_FILES['file']['error'] and small file( < 10KB) will upload successfully.

If the file exceed the limit php post_max_size or upload_max_filesize, it should get error code 1 UPLOAD_ERR_INI_SIZE. However, getting error code 3 UPLOAD_ERR_PARTIAL which is incorrect.

I guess it has something wrong with apache setting, and have no idea how to solve this problem.

Using below software and its versions

  1. php 5.6.17
  2. apache 2.4.18

Following is the php.ini:

post_max_size = 8M
file_uploads = On
upload_tmp_dir = "/tmp"
upload_max_filesize = 2M

and when upload larger file(hi.png) the error log in /var/log/httpd-error.log

PHP Notice:  Missing mime boundary at the end of the data for file hi.png in Unknown on line 0

here are index.php

<!DOCTYPE html>
<html>
<body>
    <form action='upload.php' method='post' enctype='multipart/form-data'>
    Select image to upload:
    <input type='file' name='fileToUpload' id='fileToUpload'>
    <input type='submit' value='Upload Image' name='submit'>
    </form>
</body>
</html>

and the upload.php

<?php
if($_FILES['fileToUpload']['error'] > 0){
    echo "error code".$_FILES['fileToUpload']['error']."<br>";
}
else{
    echo "file name:".$_FILES['fileToUpload']['name']."<br>";
    echo "file type:".$_FILES['fileToUpload']['type']."<br>";
    echo "file size:".$_FILES['fileToUpload']['size']."<br>";
    echo "file path:".$_FILES['fileToUpload']['tmp_name']."<br>";

    move_uploaded_file($_FILES['fileToUpload']['tmp_name'],"uploads/".$_FILES['fileToUpload']['name']);
}
?>

解决方案

I had the same problem in a FreeBSD 10.1 jail with php 5.6.18 and apache 2.4.18: Files above 7950 bytes would constantly and consistently fail with error 3, no matter which limits were set.

After ages I finally isolated the issue: The PHP module (mod_php56) was compiled with apache2filter SAPI but enabled as a handler via AddHandler. The solution was to review the port options and rebuild mod_php56 with standard options (without AP2FILTER).

Long story: Check if you have port option OPTIONS_FILE_SET+=AP2FILTER (Apache 2 Filter SAPI) on, but PHP configured the usual way as a handler ( AddType application/x-httpd-php .php ). Removing the option (as the default build/port does), and rebuilding the mod_php56 package solved the problem for me.

To verify if this is your case too, you can echo the php_sapi_name(). if it is apache2filter but php is enabled via AddHandler directive, you have the same problem. After rebuild, your php_sapi_name() should be apache2handler. Both options are also checkable in phpinfo(), as "Apache 2.0 Filter" and "Apache 2.0 Handler" respectively.

Note that this does not explain why it actually broke uploads (or why the module worked with the Handler configuration in the first place). You might also succeed by enabling mod_php as a filter instead as a handler, but I did not check that here.

这篇关于PHP上传文件错误代码3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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