SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Non-Member lostseed's Avatar
    Join Date
    Sep 2005
    Location
    Zurconion Soon!
    Posts
    1,549
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error Message in $_FILES

    I need help with this code. I'm trying to upload a file but I always get the error message: Possible file upload attack!

    I don't understand why.

    Can someone please help me?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    
    <form action="test_upload.php" method="post" enctype="multipart/form-data">
    <p>Pictures:
    <input type="file" name="pictures" />
    <input type="submit" value="Send" />
    </p>
    </form>  
    
    </body>
    </html>
    Code:
    $uploaddir = '/pictures/upload/';
    $uploadfile = $uploaddir . basename($_FILES['pictures']['name']);
    if (move_uploaded_file($_FILES['pictures']['tmp_name'], $uploadfile))
    {
       echo "File is valid, and was successfully uploaded.\n";
    }
    else
    {
       echo "Possible file upload attack!\n";
    }
    //echo basename($_FILES['pictures']['name']);
    echo '<br>';
    echo $uploadfile;

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $uploaddir needs to be an absolute path, so try:

    $uploaddir = $_SERVER['DOCUMENT_ROOT'].'/pictures/upload/';

  3. #3
    SitePoint Guru enygmadae's Avatar
    Join Date
    Sep 2002
    Location
    Dallas, Tx.
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The file couldn't be moved for some reason...check to be sure that $uploaddir and $uploadfile are what you think they need to be (echo them out)...
    PHP News, Views and Community: http://www.phpdeveloper.org

  4. #4
    Non-Member lostseed's Avatar
    Join Date
    Sep 2005
    Location
    Zurconion Soon!
    Posts
    1,549
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks!!! was the uploaddir absolute path


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
  •