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 5 of 5
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    25
    Thanks
    6
    Thanked 0 Times in 0 Posts

    $_FILES['userfile']['tmp_name'] is empty!

    I have had a file upload on my site for about a year, and all of a sudden it stopped working. I identified the problem is that the tmp_name is empty. I have way more than enough space on the server, so that isn't the problem.

    PHP Code:
                    if($_FILES['userfile']['name'] != "") {
                             
    $allowed_filetypes = array('.gif','.jpg','.jpeg','.png','.JPG','.GIF','.JPEG','.PNG');
                              
    $max_filesize 2097152// (currently 2.0MB).
                              
    $upload_path './bgimages/';
     
                           
    $filename $_FILES['userfile']['name'];
                           
    $ext substr($filenamestrpos($filename,'.'), strlen($filename)-1);

                        list(
    $width$height$type$attr) = getimagesize($_FILES['userfile']['tmp_name'] );
                        if (
    $width 1920 || $height 1200)
                            
    $error "Maximum width and height exceeded. The maximum size is 190x150.";
     
                           if(!
    in_array($ext,$allowed_filetypes))
                                  
    $error "The file you attempted to upload is not allowed.";
     
                           if(
    filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
                                 
    $error "The file you attempted to upload is too large.  2MB maximum.";
     
                           if(!
    is_writable($upload_path))
                                  
    $error "You cannot upload to the specified directory, please CHMOD it to 777.";
     
                        if (empty(
    $error)) {
                            
    $filename $user_id $_FILES['userfile']['name'];
                              if(
    move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path $filename))
                                   
    $msg "Your file upload was successful.";
                               else
                                    
    $error "There was an error during the file upload. Please try again later or contact support.";
                        } 
    Running this gives me the error: Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /patchto/public_html/settings/createtheme.php on line 68

    I also have the correct multipart/form-data enctype on the form.

    Any ideas what would cause it to suddenly stop working? I'm thinking it has to be something with the server?
    Last edited by ironj221; 05-02-2009 at 12:49 AM.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    What are you actually getting? Add the following debugging code -
    PHP Code:
    echo "<pre>";
    echo 
    "POST:";
    print_r($_POST);
    echo 
    "FILES:";
    print_r($_FILES);
    echo 
    "</pre>"
    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.

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    25
    Thanks
    6
    Thanked 0 Times in 0 Posts
    POST:Array
    (
    [theme_name] => test
    [category] => Education
    [description] =>
    [yt_link] =>
    [logo] => images/logo.png
    [searchbar] => 1
    [bg_image] =>
    [MAX_FILE_SIZE] => 524288
    [bg_color] =>
    [link_color] =>
    [menu_border] =>
    [menu_hover] =>
    [menu_bg] =>
    [privacy] => 0
    [style] => 1
    [CreateTheme] => Create theme
    )
    FILES:Array
    (
    [userfile] => Array
    (
    [name] => amy.jpg
    [type] =>
    [tmp_name] =>
    [error] => 2
    [size] => 0
    )

    )

    Well that is strange.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    A) Real code always checks for errors before blindly accessing data that might not exist,
    B) Here the link to the documentation that tells you what that error code means - 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:

    ironj221 (05-02-2009)

  • #5
    New Coder
    Join Date
    May 2008
    Posts
    25
    Thanks
    6
    Thanked 0 Times in 0 Posts
    What a silly mistake on my part. I was using MAX_FILE_SIZE as a hidden input, but it was a lower value than the php check, duh!

    Thanks for the help!


  •  

    Posting Permissions

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