我有一個很好用的圖片上傳表單!對我來說......似乎幾乎每個人都會有錯誤!這是怎麼回事? (!我知道我的節目是馬虎,我不是在尋找的批評,只是一個權宜之計請幫助。)圖片上傳表單適用於某些人,但不適用於其他人?
形式:
<form enctype="multipart/form-data" action="imgupload.php" method="POST">
Image upload:
<input name="uploadedfile" type="file" />
<input type="submit" value="Upload" />
</form>
表單處理程序:
<?php
if (($_FILES["uploadedfile"]["type"] == "image/jpeg")
&& ($_FILES["uploadedfile"]["size"] < 4000000))
{
// Where the file is going to be placed
$target_path = "/images/";
/* Add the original filename to our target path.
Result is "images/filename.extension" */
//////////RENAME FILE/////////////
$filetype = pathinfo($_FILES['uploadedfile']['name'], PATHINFO_EXTENSION);
$oldtitle = $_FILES["uploadedfile"]["name"];
$take_file_extension = substr($oldtitle, 0, strrpos($oldtitle, '.'));
$title = "jeep_".$take_file_extension.".".$filetype;
$target_path = $target_path . $title;
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The picture ". basename($_FILES['uploadedfile']['name']).
" has been uploaded<br><br>----------------<br><br>";
echo "Upload: " . $_FILES["uploadedfile"]["name"] . "<br>";
echo "Size: " . ($_FILES["uploadedfile"]["size"]/1024) . " Kb<br>";
}
}
else
{
echo "There is a file size limit of 1MB. Only JPG's can be uploaded!";
}
?>
Works的我每次都會得到「有1MB的文件大小限制,只有JPG可以上傳!」錯誤。
可能是他們正在上傳png,gif,bmp? – itachi 2012-03-27 02:46:10
不,不專門爲jpgs工作。 – user1142872 2012-03-27 02:55:32