So I’m working on a website for my mom where she wants to upload photo’s from her camera, I first tested my code with a normal picture that I found on my computer that was created in photoshop CS6 and the $_FILES array was okay:
array ( 'img' => array ( 'name' => array ( 0 => 'pic01.jpg', ), 'type' => array ( 0 => 'image/jpeg', ), 'tmp_name' => array ( 0 => 'D:\xampp\tmp\phpF0F7.tmp', ), 'error' => array ( 0 => 0, ), 'size' => array ( 0 => 6311, ), ), )
but when I try to upload a photo of my phone and hers I get the following array:
array ( 'img' => array ( 'name' => array ( 0 => 'IMG_20180228_143837.jpg', ), 'type' => array ( 0 => '', ), 'tmp_name' => array ( 0 => '', ), 'error' => array ( 0 => 1, ), 'size' => array ( 0 => 0, ), ), )
as you can see the type, tmp_name and size are empty or incorrect(the size is incorrect). I also see that the error array value is changed from 0 to 1.
both of these array exports are made by var_export($_FILES);
I use the following HTML code to upload the image:
<form method="post" action="updateproduct.php" enctype="multipart/form-data">{
<input name="img[]" id="fileupload" type="file" multiple />
I hope I have given enough information if not please say so.
2
Answers
An error value of 1 in your
$_FILES
array means you’ve exceeded the file size limit imposed by the server:Source
By default PHP accepts file uploads just under 2MB. Consider changing it to something more realistic (like 200MB) in your PHP config (
php.ini
). Also do not forget to increase another relevant option post_max_size, which should be somewhat larger than upload_max_filesize.Btw, here’s a nice helper function that will translate encoded error to the human readable message: