2
'<?php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?> '
我試過應用/ PDF ....如何上傳PDF文件?我可以得到JPG和PNG上傳到我的網站,但我不能爲DOC,TXT和PDF。我知道這個代碼是用於$ allowedExts = array(「jpg」,「jpeg」,「gif」,「png」);只有,但如何改變|| ($ _FILES [「file」] [「type」] ==「image/jpeg」)爲|| ($ _FILES [「file」] [「type」] ==「application/pdf」)? Thanx提前...我試過應用程序/ pdf ....如何上傳pdfs?
不要忘記申請/ octetstream如果一開始不承認... – mkl
感謝名單,我都試過,但還是回來爲無效。 @HMarioD – amreed8
@ amreed8我延長了答案,看一看。 – HMarioD