Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
01-09-2013, 03:11 AM #1
Why cant i check for $_FILES without element
Hi i been fighting this deal to figure out why its not posting with no file upload and i just found that if i do
This works fine
if($_FILES['value']['name'] == "")
Just fyi im checking if no file upload then do a dif process.
update is it that if you have it turned on then $_FILES always exists no matter what its just the name that is blank?
Last edited by durangod; 01-09-2013 at 05:05 AM.
01-09-2013, 04:40 AM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,662 Times in 2,631 Posts
Not sure what you mean by "turned on", but $_FILES will always exist so long as you have an input type of file (and have a enc type of multipart/form-data of course).
By providing it with no file, than you can still find an offset in $_FILES under your input name. Since the very first thing you should do with the upload is determine if it was successful, you can check the $_FILES['value']['error']. Failing to fill select a file will result in an error code of UPLOAD_ERR_NO_FILE (the integer value of 4).
So to check no file in particular, you would use:
The only valid upload to allow you to continue is an error value of UPLOAD_ERR_OK or the integer 0.PHP Code:
if ($_FILES['value']['error'] == UPLOAD_ERR_NO_FILE)
You can find all the error codes for uploads here: http://php.ca/manual/en/features.file-upload.errors.php
Users who have thanked Fou-Lu for this post:
01-09-2013, 05:03 AM #3
Thanks sorry, yeah by turned on i meant having this in my form - multipart/form-data
learn something new every day, i never knew it was there regardless, makes me think i should go back and check some of my older coding now.... it never ends lmao hee hee