我正在嘗試測試一個簡單的文件上傳腳本,但失敗。這是html部分。無法上傳文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title="testing"></title>
</head>
<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input type="file" name="uploaded"/>
<input type="submit" value="Upload File"/>
</form>
</body>
而在這下面是php部分。
<?php
$target = "upload/";
$target = $target . basename($_FILES['uploaded']['name']) ;
$ok=1;
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
它未能在這一行:
如果(move_uploaded_file($ _ FILES [ '上傳'] [ 'tmp_name的值'],$目標))
,並執行其他部分:「對不起,上傳文件時出現問題。「我怎樣才能讓它在沒有失敗的情況下工作。謝謝你的幫助。
你有權限寫你想要移動它的文件嗎 – Anigel
恕我直言,下面的SO問題有很多關於PHP文件上傳的有用信息http://stackoverflow.com/questions/3501749/php-move-上傳的文件錯誤 –