Results 1 to 17 of 17

Thread: [RESOLVED] Php File Upload

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Resolved [RESOLVED] Php File Upload

    Ok I must have done this about 20 times in the past but for some reason I cant get my latest file upload to work?

    Errors :

    Code:
    Possible file upload attack!
    Here is some more debugging info:Array
    (
        [uploadedfile] => Array
            (
                [name] => aces.jpeg
                [type] => image/jpeg
                [tmp_name] => /home/identisysuk/public_html/tmp/phpFaqFr0
                [error] => 0
                [size] => 50985
            )
    
    )
    And code -

    PHP Code:
    $uploaddir '/home/identisysuk/public_html/uploads/';
    $uploadfile $uploaddir "tempFile";

    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";
    }

    echo 
    'Here is some more debugging info:';
    print_r($_FILES);
    //Print the error handle out here

    print "</pre>"
    The uploads directory has the correct permissions so that shouldn't be a problem! Any assistance? This has to be somthing daft, its just one of them days!

    Thanks

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Php File Upload

    try taking away the last / on the uploaddir

    PHP Code:
    $uploaddir '/home/identisysuk/public_html/uploads'
    My usual boring signature: Something

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Php File Upload

    Thanks but the issue still remains still producing the same error code of 0 :-/

    Pino

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Php File Upload

    I'm getting a little frustrated with this now, can anyone help?

  5. #5
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Php File Upload

    Where is your script located?

    If it is located in public_html then you just need the upload directory to be 'uploads'
    My usual boring signature: Something

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Php File Upload

    its actually in a sub folder off public_html (public_html/Admin)

  7. #7
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Php File Upload

    then the upload directory should be

    '../uploads'
    My usual boring signature: Something

  8. #8
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Php File Upload

    I don't think it's that. He has a / at the beginning so it will go to the root, then follow the path.

    I reckon it's because your new filename has no extension therefore the move function will see the filename as a folder and break.
    Chris

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Php File Upload

    I'm not sure I follow, how would i add the extension on then?

    Thanks

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Php File Upload

    Quote Originally Posted by the182guy
    I reckon it's because your new filename has no extension therefore the move function will see the filename as a folder and break.
    Not true. File name extensions aren't required on either *nix or Windows.

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Php File Upload

    Your debug output says 'uploadedfile' but in the code you're using $_FILES['userfile']. Change this to $_FILES['uploadedfile'].

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Php File Upload

    Thanks Pengate, my code is below.

    PHP Code:
    //First do the file uploads
    $target "../uploads/";
    $target $target basename$_FILES['uploadedfile']['name']) ;

    //If everything is ok we try to upload it


            
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target))
                {
                    echo 
    "The file ".
                    
    basename$_FILES['uploadedfile']['name']). " has been uploaded";
                }
                else
                {
                echo 
    "Sorry, there was a problem uploading your file.";
                } 
    no luck still. this should be one of the easiest things to do.

    Thanks
    Last edited by Pino; Nov 5th, 2007 at 04:50 AM.

  13. #13
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Php File Upload

    What does the HTML for the file input control look like?

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Php File Upload

    Thanks.

    Code:
    <form enctype='multipart/form-data' action='addProduct.php' method='POST'>
    <input type='hidden' name='MAX_FILE_SIZE' value='100000' />
    <input name='uploadedfile' type='file' />
    </form>

  15. #15
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Php File Upload

    Try this:

    PHP Code:
    define('UPLOAD_DIR''../uploads/');

    // attempt to move the file
    if (isset($_FILES['uploadedfile']))
    {
      
    $target UPLOAD_DIR $_FILES['uploadedfile']['name'];

      if (
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target) === true)
      {
        echo 
    'Success: ' $_FILES['uploadedfile']['name'] . ' uploaded.';
      }
      else
      {
        echo 
    'Failed to move file: ';

        
    $errors = array(
          
    UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
          
    UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
          
    UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded.',
          
    UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
          
    UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.',
          
    UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.',
          
    UPLOAD_ERR_EXTENSION => 'File upload stopped by extension.'
        
    );
        
        if (
    array_key_exists($err $_FILES['uploadedfile']['error'], $errors))
          echo 
    $errors[$err];
        else
          echo 
    'Unknown error: ' $err;
      }
    }
    else
    {
      echo 
    'No file was uploaded.';


  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Php File Upload

    worked.....

    Whats differant?

    Thanks

  17. #17
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Php File Upload

    Nothing that I can see. I don't know why yours didn't work. Perhaps you had a typo somewhere.


Posting Permissions

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



Click Here to Expand Forum to Full Width