Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2013, 02:11 AM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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

PHP Code:
if($_FILES['value']['name'] == ""
these do not

PHP Code:
if(!$_FILES)
if(!
$_FILES['value']) 
Im curious why i have to include the name element to get it to work, is that normal?
Just fyi im checking if no file upload then do a dif process.

Thanks


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 04:05 AM..
durangod is offline   Reply With Quote
Old 01-09-2013, 03:40 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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:
PHP Code:
if ($_FILES['value']['error'] == UPLOAD_ERR_NO_FILE
The only valid upload to allow you to continue is an error value of UPLOAD_ERR_OK or the integer 0.

You can find all the error codes for uploads here: http://php.ca/manual/en/features.file-upload.errors.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
durangod (01-09-2013)
Old 01-09-2013, 04:03 AM   PM User | #3
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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
durangod is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:51 AM.


Advertisement
Log in to turn off these ads.