我在將圖像上載到服務器時遇到了一些問題。圖像應被上傳到目錄IteamImages和名稱應該是格式爲:$ userid_ $ date.png圖像上傳PHP問題
兩個問題:
的圖像似乎沒有在目錄中顯示
圖像名稱顯示爲:上傳/ Array_20140906072547.png(代替上傳 /4_20140906072547.png)
$UserId=$_POST['UserId'];
$uploaddir = "IteamImages/";
$DateLastEdit = $UserID."_".date("YmdHis");
$dateCreates = date("Y-m-d H:i:s");
$file = $DateLastEdit.".png";
$uploadfile = $uploaddir . $file;
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"]/1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"].$file;
}
if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {
move_uploaded_file($_FILES["file"].$file,
"upload/" . $_FILES["file"].$file);
echo "Stored in: " . "upload/" . $_FILES["file"].$file;
}
mysql_query("UPDATE ItemDetails SET ItemImage='$file' WHERE UserID ='$UserID' AND Id='$last'");
這是HTML形式的一部分:
<form action="manual-item-post.php" method="post" enctype="multipart/form-data">
UserId: <input type="text" name="UserId"><br>
<label for="file">Image Upload:</label><br>
<input type="file" name="file" id="file"><br>
<input type="submit">
</form>
感謝您的徹底解答。我解決了這兩個問題。 – user2913669 2014-09-06 11:57:37