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

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Problems with move_uploaded_file


    Hi Folks,

    I'm trying to create an upload page on one of my websites. It works but only up to file sizes of 100k. I'm using move_uploaded_file and, like I said, it works fine with files that are less than 100k. I ran phpinfo on the site and it listed the max_file_uploads as 20 which I'm guessing means I should be able to upload files up to 20MB right? Any suggestions would be very helpful. The error I'm getting is "Notice: Undefined offset: 0 in /hsphere/local/home/c336918/netfedcu.org/admin/uploader.php on line 25"

    Thanx!
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,551
    Rep Power
    2337
    Looks like on line 25 of the file "uploader.php" you are accessing the 0th index of an array which has no 0th index.

    Without code, that's the best we can do.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    max_file_uploads is the number of file uploads allowed, it has nothing to do with the size.

    upload_max_filesize and post_max_size both control how large your file uploads can be.
    Last edited by E-Oreo; October 6th, 2012 at 08:17 PM.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    While I know you really can't say much without the code I don't think it's coding issue - but here it is.

    <?php include 'passwordProtectPage.php'; ?>
    <?php
    require_once 'template.php';
    echo head('NET Federal Credit Union Website Administration');
    ?>
    <?php
    echo nav();
    ?>
    <?php
    ini_set('display_errors',1);
    error_reporting(E_ALL);

    $target_path = "../download/";

    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

    echo "<div class='art-content-layout'><div class='art-content-layout-row'><div class='art-layout-cell art-content'><div class='art-post'><div class='art-post-body'><div class='art-post-inner art-article'><h2 class='art-postheader'>Newsletter Upload Management</h2><div class='art-postcontent'>";

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try again! [" . $target_path . "]";
    $html_body = '<h1>File upload error!</h1>';
    switch ($_FILES[0]['error']) {
    case 1:
    $html_body .= 'The file is bigger than this PHP installation allows';
    break;
    case 2:
    $html_body .= 'The file is bigger than this form allows';
    break;
    case 3:
    $html_body .= 'Only part of the file was uploaded';
    break;
    case 4:
    $html_body .= 'No file was uploaded';
    break;
    default:
    $html_body .= 'unknown errror';
    }
    echo ($html_body);
    }

    echo "</div></div></div></div></div></div></div>";
    ?>

    How can I verify what the largest file size that can be uploaded? phpinfo doesn't have that info. I can upload files up to 100k and then I get that error message. It worked correctly at one time. I have a client who uploads their PDF newsletters using this (and the initial form that allows them to select the file this is the code that actually uploads). Thanks for your help! If there's another way to upload files via php that would make more sense I'm all ears.
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    Something like
    PHP Code:
    <?php
    echo min(ini_get('upload_max_filesize'), ini_get('post_max_size')) . ' bytes';
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    Thanks - that at least helped verify the file size I can upload. So I ran it and the answer is 20M Bytes. Still it seems odd that I can upload files that are less than 100k but nothing larger and I know when I implemented it I was uploading 600k files. Any other suggestions would be greatly appreciated.
  12. #7
  13. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    If it gave you '20M' as the output it might not be accurate; I was expecting it to normalize the values to integer bytes but I guess it didn't. You should output them separately and compare them visually instead.

    Regardless, if you fix your switch statement the notice will go away and you might get useful error output:
    PHP Code:
    switch ($_FILES['uploadedfile']['error']) { 
    Since it isn't throwing an error about $_FILES['uploadedfile'] being undefined you're not exceeding post_max_size, but you might still be exceeding upload_max_filesize. If that's the case it should give you error 1 after you fix the switch.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo