简体   繁体   中英

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'); and every time I restart wamp services and it's still the same, only uploading files less that 2MB only! any suggestions?

move_uploaded_files() does NOT care how big (or small) the uploaded files are. 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. This has to be done at the php.ini level (or httpd.conf/.htaccess). The various settings are listed here: http://www.php.net/manual/en/features.file-upload.post-method.php

b) You need to add error handling, to catch when uploads DO fail. 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

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

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

or via htaccess (if its allowed on your server)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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