當我使用這段代碼上傳一個文件時,它會將該文件的一個副本放在「uploads」文件夾中(這正是我想要的),但它也將一個副本放在我的根目錄中。我只希望文件進入上傳文件夾。爲什麼我的文件上傳代碼會將2套文件放入我的目錄中? (PHP)
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>';
此代碼確實不應在上傳目錄之外創建文件。您的PHP上傳臨時路徑是否設置爲根目錄或者其他奇怪的東西? – 2010-04-04 19:50:35
你能指定文件準確放入哪個目錄嗎? – 2010-04-04 19:51:05