SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot dadofgage's Avatar
    Join Date
    Feb 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why would the $_FILES['userfile']['name'] be empty/blank?

    Ok, I have a basic script to upload an image.

    PHP Code:
    <?php

    $uploaddir 
    '/public_html/myfolder/mysubfolder/';
    $uploadfile $uploaddir basename($_FILES['userfile']['name']);

    echo 
    $_FILES['userfile']['name'].'<br>';
    echo 
    $uploaddir.'<br>';
    echo 
    $uploadfile.'<br>';

    echo 
    '<pre>';
    if (
    move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
       echo 
    "File is valid, and was successfully uploaded.\n";
    } else {
       echo 
    "Possible file upload attack!\n\n";
    }

    echo 
    'Here is some more debugging info:';
    print_r($_FILES);

    print 
    "</pre>";
    The form has the proper enctype="multipart/form-data" attribute on it.

    When this uploads, the first echo $_FILES['userfile']['name'] is blank.

    But when the print_r($_FILES) is executed, it shows:

    HTML Code:
    Here is some more debugging info:Array
    (
        [filebyuser] => Array
            (
                [name] => kramer.jpg
                [type] => image/jpeg
                [tmp_name] => /tmp/phpplFX2y
                [error] => 0
                [size] => 32910
            )
    
    )
    What am I missing here?

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The element 'userfile' in the file array is merely an example name used on many tutorial sites. Your form element is called filebyuser so that's what you have to use.

    $_FILES['filebyuser']['name'] will not be blank.

    Hope this fixes your problem.

  3. #3
    SitePoint Zealot dadofgage's Avatar
    Join Date
    Feb 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, now I get a different error:

    move_uploaded_file(/home/myname/public_html/folder/uploadedfiles/napoleon.jpg): failed to open stream: Permission denied in ...

  4. #4
    SitePoint Zealot arun_md's Avatar
    Join Date
    Aug 2005
    Location
    chennai
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In this error You have to set all access permission to that folder.

    By use of chmod(foldername,0777) first you set this permission to your uploading folder , then you won't get that error.

  5. #5
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure that you have write permission to the folder that you are trying to upload the picture to.

    Edit:

    Just as he ^ said

  6. #6
    SitePoint Zealot dadofgage's Avatar
    Join Date
    Feb 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, I thought the permissions were set correctly, but obviously not.

    Thanks for your help.

    This is appreciated!


Bookmarks

Posting Permissions

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