Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 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:
    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

  • Users who have thanked Fou-Lu for this post:

    durangod (01-09-2013)

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •