我是新來的PHP。我試圖上傳一個文件到我的本地服務器,但它一直不成功。PHP上傳文件不成功
我所有的文件都在/ var/www/html/ 但是我在html文件夾中創建了一個名爲uploads的文件夾,我將其權限更改爲777(我平均搜索的內容是最適合我的需求的)
這是我的代碼: 的index.html
<!DOCTYPE html>
<html>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
upload.php的
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES['fileToUpload']['name']);
echo "Target File: " . $target_file . "<br />";
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
幫助,這將非常感激。由於
線索的價值:看看你輸入名字另外兩個在'$ _FILES'數組中。仔細看看那些人。你會找到你自己的答案,並且會執行你的第一個調試操作。 ;-) –
撇在一邊:很少有任何理由想要'777' – CD001
@ CD001可能認爲如果文件夾被設置爲755,並且不起作用,那麼777「必須」工作。 –