简体   繁体   English

在本地主机上上传图像时获取UPLOAD_ERR_PARTIAL

[英]Getting UPLOAD_ERR_PARTIAL when uploading images on localhost

I'm working on a simple html form to upload an image, then save it on a directory situated on my localhost. 我正在使用一个简单的html表单上载图像,然后将其保存在本地主机上的目录中。

<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. 但是,当我处理图像时,在检查错误(在$ _FILES ['image'] ['errors']中时,出现错误3,这意味着文件仅部分上传了)。

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. 我已经完成了所有错误检查,确实将enctype =“ multipart / form-data”放在了表单上,而我在这里基本上一无所知。

Thank you for your time. 感谢您的时间。

You have to check your PHP configurations on php.ini file. 您必须在php.ini文件中检查您的PHP配置。 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. 如果您的上传不断被中断,则您需要增加最大上传大小或增加PHP脚本超时的时间。 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. 您可以使用ini_set函数增加PHP配置文件或增加脚本。 Check the manual for more details. 有关更多详细信息,请查阅手册。 PHP Manual PHP手册

I also got the UPLOAD_ERR_PARTIAL error, and the variables post_max_size , upload_max_filesize and max_execution_time were set correctly. 我也收到UPLOAD_ERR_PARTIAL错误,并且正确设置了变量post_max_sizeupload_max_filesizemax_execution_time I then tried to upload a very small file (2 Byte), as suggested by Kirogo , and I got the following warnings: 然后,我尝试按照Kirogo的建议 上传一个非常小的文件 (2字节),并且收到以下警告:

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. 修复服务器上的文件/目录权限后,上载再次起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM