Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

apache - php upload file error code 3

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']);
}
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...