#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    382
    Rep Power
    47

    Error in File upload Routine


    Hi:

    I have a routine which allows a user to upload a pdf file to a server. It works on files smaller than 2MB but fails on file that are larger.

    The code is here:

    PHP Code:
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        
    chmod$target_path 0644 );
        echo 
    "<br><font color=\"#FF0000\">The file ".  basename$_FILES['uploadedfile']['name']). 
        
    " has been uploaded and named $full_file_name</font>";

    } else{
        echo 
    "<br><font color=\"#FF0000\">There was an error uploading the file, please try again!</font>";

    The hosting company says they have increased the file upload limit to 20MB but the routine still fails...

    How can I find out exactly why the program is failing? How can I replace the "There was an error..." message with the actual error encountered?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,399
    Rep Power
    594
    $_FILES contains error codes. Put this in your else block instead:
    PHP Code:
    else {
      switch (
    $_FILES['uploadedfile'] ['error'])
             {  case 
    1:
                       print 
    '<p> The file is bigger than this PHP installation allows</p>';
                       break;
                case 
    2:
                       print 
    '<p> The file is bigger than this form allows</p>';
                       break;
                case 
    3:
                       print 
    '<p> Only part of the file was uploaded</p>';
                       break;
                case 
    4:
                       print 
    '<p> No file was uploaded</p>';
                       break;
             }

    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    Originally Posted by SeanF
    The hosting company says they have increased the file upload limit to 20MB but the routine still fails...
    They LIED!

    [edit] Maybe not
    Last edited by requinix; April 16th, 2013 at 10:25 PM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    382
    Rep Power
    47
    Originally Posted by gw1500se
    $_FILES contains error codes. Put this in your else block instead:
    PHP Code:
    else {
      switch (
    $_FILES['uploadedfile'] ['error'])
             {  case 
    1:
                       print 
    '<p> The file is bigger than this PHP installation allows</p>';
                       break;
                case 
    2:
                       print 
    '<p> The file is bigger than this form allows</p>';
                       break;
                case 
    3:
                       print 
    '<p> Only part of the file was uploaded</p>';
                       break;
                case 
    4:
                       print 
    '<p> No file was uploaded</p>';
                       break;
             }

    Thanks for the reply... this is great!

    The response I get now is:
    There was an error uploading the file:
    The file is bigger than this form allows
    So it appears now that the file is too big for the form..

    I added:
    PHP Code:
    <input type = \"hidden\" name=\"MAX_FILE_SIZE\" value=\"6144000\"> 
    to the form and it works fine... thanks for your help.
    Last edited by SeanF; April 16th, 2013 at 10:28 PM.

IMN logo majestic logo threadwatch logo seochat tools logo