我正在實現一個代碼,使用PHP將圖片上傳/保存到服務器。用php上傳圖片,一些圖片不上傳
一些圖像上傳和保存,很好。這些圖片是我從互聯網上下載的照片或其他人給我的照片。
但是我用我自己的數碼相機拍的照片不上傳,我得到「無效文件」。現在,我的照片是.JPG
。我更改了代碼以包含JPG
字符串。我在php.ini
上檢查並編輯upload_max_filesize
,所以它不是這個尺寸。
我使用PHP 5.3.13
任何想法?這是什麼魔法?
編輯
也許它是我的圖片的元數據?數碼相機的設置?有沒有解決方法?
在此先感謝
這裏是服務器端
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/JPG")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 4000000)
&& 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("cultmapsite/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: " . "cultmapsite/upload" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
post_max_size呢? – markdwhite
@markdwhite'memory_limit'是128M,post_max_size是8M。 'upload_max_filesize'是4M。所以,根據[this](http://www.php.net/manual/en/ini.core.php#ini.post-max-size)我很好。我試圖上傳的圖片最大爲2.25M ... – slevin