【发布时间】:2013-08-22 13:44:42
【问题描述】:
我正在实现一个使用 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
memory_limit是 128M,post_max_size 是 8M。而upload_max_filesize是 4M。所以,根据this 我没问题。我尝试上传的图片最大为 225 万...
标签: php image file-upload