Why would PHP $_FILES[] array go empty.

Sunday, September 07, 2008

If you're finding that $_FILES[] array is empty after submitting the form with file input, then first make sure that you have the form enctype attribute is set to "multipart/form-data".

That is as below:
<form enctype="multipart/form-data">
<input name="myFile" type="file">
...
</form>



If enctype attribute is not set in the form, then it would take default value for it as "application/x-www-form-urlencoded", which will make the form not send any file data to target program/PHP file.

If $_FILES array remains empty even after setting enctype right, you should check against other settings in your PHP server to make sure it allows the server to upload files.

2 comments:

Bluesforte 10:27 AM  

Thank you very much! Simple problem but hard to find info on it...the enctype worked like a charm :)

mrben 4:44 AM  

Sweet! Thank you so much! Wasted hours on this!!

Back to TOP