简体   繁体   English

PHP move_uploaded_files()函数不适用于超过2MB的图片

[英]PHP move_uploaded_files() function not working with pics sizes more than 2MB

Peace be with you all, I have an issue that is whenever I try to use the function 大家都安心,我有一个问题,就是我每次尝试使用该功能时

move_upload_files()
I find it working perfectly with images less than 2MB and I have modified my php.ini and used ini_set('upload_max_filesize', '10M'); 我发现它可以完美地用于小于2MB的图像,并且我已经修改了php.ini并使用了ini_set('upload_max_filesize', '10M'); and every time I restart wamp services and it's still the same, only uploading files less that 2MB only! 每次我重新启动wamp服务时,它仍然是一样的,仅上传小于2MB的文件! any suggestions? 有什么建议么?

move_uploaded_files() does NOT care how big (or small) the uploaded files are. move_uploaded_files()不在乎上传文件的大小。 It simply moves them. 它只是移动它们。 Most likely you've got a system-set upload limit causing the uploads to be aborted. 您很可能具有系统设置的上传限制,导致上传被中止。 Since you're here asking this question, it implies you have absolutely NO error handling in your upload script and simply assume that all uploads will always succeed. 由于您是在问这个问题,因此它意味着您的上载脚本中绝对没有错误处理,并且仅假设所有上载将始终成功。

a) You need to increase your upload limit. a)您需要增加上传限制。 This has to be done at the php.ini level (or httpd.conf/.htaccess). 这必须在php.ini级别(或httpd.conf / .htaccess)上完成。 The various settings are listed here: http://www.php.net/manual/en/features.file-upload.post-method.php 此处列出了各种设置: http : //www.php.net/manual/zh/features.file-upload.post-method.php

b) You need to add error handling, to catch when uploads DO fail. b)您需要添加错误处理,以捕获上载DO失败的时间。 Something like 就像是

if ($_FILES['uploadedfile']['error'] !== UPLOAD_ERR_OK) {
   die("Upload failed with error code #" . $_FILES['uploadedfile']['error']);
}

is the absolute bare minimum. 是绝对的最低要求。 The available error codes are detailed here: http://www.php.net/manual/en/features.file-upload.errors.php 此处提供了可用的错误代码的详细信息: http : //www.php.net/manual/zh/features.file-upload.errors.php

You can try to change some other settings. 您可以尝试更改其他设置。 Check the settings by using this code: 使用以下代码检查设置:

echo ini_get('post_max_size');
echo ini_get('upload_max_filesize');

if it is lower than 10M, you can change it via 如果低于10M,则可以通过以下方式进行更改

ini_set('upload_max_filesize', '10M');

or via htaccess (if its allowed on your server) 或通过htaccess(如果您的服务器允许)

php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_execution_time 200
php_value max_input_time 200

Just to be complete, you can edit your php.ini settings to 为了完整起见,您可以将php.ini设置编辑为

upload_max_filesize = 10M
post_max_size = 10M

Another thing to check is if your form code has the correct attributes 要检查的另一件事是表单代码是否具有正确的属性

method="POST" enctype="multipart/form-data"

https://stackoverflow.com/a/12685461/2701758 https://stackoverflow.com/a/12685461/2701758

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

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