问题
I'm working on a simple html form to upload an image, then save it on a directory situated on my localhost.
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" enctype="multipart/form-data" method="post">
<label for="img">Pick a picture</label>
<input id="img" type="file" name="image">
<input type="submit" name="imageProfil" value="Upload the image">
</form>
However, when I handle the image, while checking errors (in $_FILES['image']['errors'], I'm getting an error 3, which means the file has only been partially uploaded.
Moreover, each time I upload a file, I'm not getting any response after the first response (where the exception is thrown at me). I've done all the error checking, I did put the enctype="multipart/form-data" on my form, and I'm basically clueless right here.
Thank you for your time.
回答1:
You have to check your PHP configurations on php.ini file. If your upload is constantly being interrupted you either need to increase the maximum upload size or the time before your PHP script times out. Check this variables:
post_max_size
upload_max_filesize
max_execution_time
You can either increase in your PHP configuration file or increase in your script using the ini_set function. Check the manual for more details. PHP Manual
回答2:
I also got the UPLOAD_ERR_PARTIAL
error, and the variables post_max_size
, upload_max_filesize
and max_execution_time
were set correctly. I then tried to upload a very small file (2 Byte), as suggested by Kirogo, and I got the following warnings:
Warning: move_uploaded_file(files/myfile.txt): failed to open stream: Permission denied [...]
Warning: move_uploaded_file(): Unable to move '/tmp/phps8Jdwt' to 'files/myfile.txt' [...]
After fixing the file/directory permissions on the server, the upload worked again.
来源:https://stackoverflow.com/questions/30425142/getting-upload-err-partial-when-uploading-images-on-localhost