我正在使用此腳本上傳文件。自從我第一次嘗試以來,我沒有對filetype進行任何檢查。我使用的是Ubuntu,並在php.ini文件中將文件上傳設置爲'on'。但是我仍然無法上傳文件。通過php上傳文件時出錯
<?php
if(isset($_POST['send']))
{
$uploaddir = "/home/harbhag/Desktop/";
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo $uploadfile;
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";
}
}
?>
<html>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="hidden" name="send" value="send" />
<input type="submit" value="Send File" />
</form>
</html>
什麼都在'$ uploaddir'目錄(寫)權限? – helle 2011-03-05 09:24:54
你有輸出嗎? – alexn 2011-03-05 09:26:07
@helle,自從我的主目錄以來,我對$ uploaddir具有寫權限。 @alexn,我得到了代碼中寫的「可能的文件上傳攻擊」。但是我沒有收到任何消息,說明錯誤的可能原因。 – hsinxh 2011-03-05 09:29:57