我的HTML表單代碼:文件上傳PHP不工作,我不知道爲什麼
<form action="upload.php" method="GET" enctyped="multipart/form-data">
<label for="file"> Filename:</label>
<input type="file" name="loadedFile" id="file"/></br>
<input type="submit" name="uploadItNow" value="Submit"/>
hai, this is this the uploader.
</form>
PHP文件上傳腳本:
if (isset($_GET['uploadItNow'])) // checks if submit button has pressed
{
if ($_FILES['loadedFile']["error"] > 0)
echo "Error: ". $_FILES["loadedFile"] ["error"]. "</br>";
else
{
echo "Upload: ". $_FILES["loadedFile"] ["name"]. "</br>";
echo "Type: ". $_FILES["loadedFile"] ["type"] . "</br>";
echo "Stored in: " .$_FILES["loadedFile"] ["tmp_name"];
echo "Size: ". ($_FILES["loadedFile"] ["size"]/1024). " Kb</br>";
//Copies file from TEMP_PHP dir to d.default dir
if (file_exists("." . $_FILES["loadedFile"]["name"]))
{
echo $_FILES["loadedFile"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["loadedFile"]["tmp_name"],"." . $_FILES["loadedFile"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["loadedFile"]["name"];
}
}
}
出於某種原因,它不沒有工作,我的代碼不斷去這個代碼:
echo $_FILES["loadedFile"]["name"] . " already exists. ";
嘗試在你的表單標籤爲「ENCTYPE」改變「enctyped」 – MRR0GERS
你有沒有考慮過該文件存在? –