tags:

views:

38

answers:

1

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>';
+2  A: 

What would be your temporary dir? Is it possible that somehow the uploaded file lands in the root but PHP can not delete it? Figuring this out requires a lot more knowledge about your setup.

chx
Ahh yes that was the problem. I added a @unlink($_FILES['userfile']['tmp_name']); and now it works. Thanks.
ggfan
I would be somewhat worried about the fact that your temporary directory is the root (any root!)...
Matti Virkkunen
An attacker could exploit that by uploading a file with the same name as one of your 'actual' files in the root directory. He could upload 'index.php' and your function would delete your main page!
Lotus Notes