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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    file upload confirmation question

    I have a form where the user has the option to upload an image for a group creation script I am making.

    it works great if the user uploads

    but if the user decides not to upload anything and fill out the rest of the fields then I get into problems.. the file conditional is still met and "nothing" is uploaded to the server unforunately

    Code:
    if(isset($_FILES['uploadedfile']['name'])){
    the above conditional is met whether or not the user decides to upload file in my form.. how do I make it so that the conditional is only met if an upload is made?

    thanks

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Try
    PHP Code:
    if(isset($_FILES['uploadedfile'])){ 
    You may want to read this: http://www.htmlgoodies.com/beyond/we...le.php/3560181
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Bobafart (03-04-2008)

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    no difference.. it still treats it as a positive condition that is met even when no file is uploaded...

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,010
    Thanks
    2
    Thanked 312 Times in 304 Posts
    If a type="file" field exists but nothing was entered at the time the form was submitted, the $_FILES array will be set and the ['error'] element for the field name will contain a value of 4 -
    UPLOAD_ERR_NO_FILE
    Value: 4; No file was uploaded.
    Ref - http://www.php.net/manual/en/feature...oad.errors.php
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    Bobafart (03-04-2008)

  • #5
    New Coder
    Join Date
    Mar 2008
    Location
    Lakeland, FL
    Posts
    39
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Just check if its empty instead of if its set.

  • Users who have thanked digitalfiz for this post:

    Bobafart (03-04-2008)

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,010
    Thanks
    2
    Thanked 312 Times in 304 Posts
    It won't be empty, the ['error'] element will be set. Checking the error element like I posted is the only way to tell if no file was selected and to distinguish this condition from the other errors that could occur for a file upload.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    Bobafart (03-04-2008)

  • #7
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    Quote Originally Posted by CFMaBiSmAd View Post
    If a type="file" field exists but nothing was entered at the time the form was submitted, the $_FILES array will be set and the ['error'] element for the field name will contain a value of 4 -


    Ref - http://www.php.net/manual/en/feature...oad.errors.php

    so do this?

    Code:
    if(($_FILES['uploadedfile']['error'])=='UPLOAD_ERR_NO_FILE'){

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,010
    Thanks
    2
    Thanked 312 Times in 304 Posts
    Yes, except no quotes around - UPLOAD_ERR_NO_FILE
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    Bobafart (03-04-2008)


  •  

    Posting Permissions

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