我有一個錯誤。我用HTML 5和PHP做了一個文件上傳。當我嘗試上傳任何內容時總會出現錯誤。下面的代碼:php flie上傳錯誤
<form action="upload.php" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload your file" name="submit">
</form>
upload.php的:
$target_path = "upload/";
$target_path = $target_path . basename($_FILES["fileToUpload"]["name"]);
if(isset($_POST["submit"])) {
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_path)) {
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
的目標部分,你在哪裏最初定義'是在'如果(file_exists($ TARGET_FILE使用$ target_file' )){'?我想你需要在那裏使用'$ target_path'!此外,你應該在你的問題中包含錯誤,而不僅僅是「總是有錯誤」 – RamRaider
請按照我希望它對你有用的鏈接。 http://stackoverflow.com/questions/1673393/php-file-upload –
只需更改move_uploaded_file調用的目標部分的文件名\t 'if(move_uploaded_file($ _ FILES [「fileToUpload」] [「tmp_name」], $ target_file))' – Codeone