www.webdeveloper.com
Results 1 to 7 of 7

Thread: File upload with PHP

  1. #1
    Join Date
    Nov 2013
    Posts
    72

    File upload with PHP

    Hi all. I have been trying to figure out what is going on with my code but I am stumped. It's a simple upload script but for some reason, when I do the empty test and the bool error test, they are returning empty and false and I do not understand why.

    Any help is appreciated

    HTML Code
    Code:
    <form class='admin_form' action='' method='POST' enctype='multipart/form-data'>
                        <fieldset>
                            <h2>Comic Page Upload</h2>
                            <label for='comic_page'>Filename</label>
                            <input type='file' name='comic_page' id='comic_page'>
                            <input type='submit' name='comic_page_btn' value='Upload'>
                            <span id='comic_page_upl_err_msg'>".$err_msg."</span>
                        </fieldset>
    </form>
    PHP Code
    Code:
    if(isset($_POST['comic_page_btn'])){
           
            if((!empty($_FILES['comic_page'])) && ($_FILES['comic_page']['error'] == 0)) {  
                    //Do all the stuff to upload file
                    // Didn't add the code that goes here since it's not the issue, at least not yet
            }else{
                  echo "Error: No file uploaded";
                  // This is the output because the array is empty and the error array is false(== 0).
    
           }
    }

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,322
    Maybe do a var_dump() or var_export() of $_FILES to see what you received, and what, if anything, is in the error element?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2013
    Posts
    72
    var_dump() or var_export() are both returning NULL which is what I suspected although for the life of me, I can't figure out why.

    Once the script is called, the $_FILES array is supposed to grab the file information right? I can't find an issue with the code. Is it possible that there is an issue with the server. Some ini setting or something like that that I need to change?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,322
    From the PHP side of things, you could look at these config params: http://php.net/manual/en/ini.core.php#ini.file-uploads

    Other than that, I suppose it could be something in the web server config? (Not my strong suit)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jul 2014
    Posts
    1
    http://www.phptrick.in/php-file-uploading/

    Check out this link for a deailed study

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,346
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #7
    Join Date
    Nov 2013
    Posts
    72
    I finally figured this out. I also had a logout form on the page which only contained a submit button but I missed the form closing tag and this caused the upload form not to work. Crazy huh. I closed the logout form and the upload code worked fine after that.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles