Getting UPLOAD_ERR_PARTIAL when uploading images on localhost

血红的双手。 提交于 2021-02-11 07:55:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!