Why is my upload-of-a-file code putting 2 sets of files into my directory? (PHP)

Posted by ggfan on Stack Overflow See other posts from Stack Overflow or by ggfan
Published on 2010-04-04T19:44:34Z Indexed on 2010/04/04 19:53 UTC
Read the original article Hit count: 229

Filed under:

When I upload a file using this code, it puts a copy of the file in the "uploads" folder(which is what I want) but it also puts a copy in my root. I only want the files going to the uploads folder.

    define ('GW_UPLOADPATH', 'uploads/');
$upfile= GW_UPLOADPATH . $_FILES['userfile']['name'];

if(is_uploaded_file($_FILES['userfile']['tmp_name']))
{
    if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) //this is saying if the file isn't moved to $upfile.
    {
        echo 'Problem: could not move file to destination directory';
        exit;
    }
}
else
{
    echo 'Problem: Possible file upload attack. Filename: '; //this could be an attack b/c it might be from localhost.
    echo $_FILES['userfile']['name'];
    exit;
}

echo 'File uploaded successfully<br><br>';

© Stack Overflow or respective owner

Related posts about php