我在 PHP.Image 中上传图像是.jpg类型,但是在上传时,它给了我错误0。
这是我的代码。
if(isset($_FILES["image_file"]["name"])){
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["image_file"]["name"]));
if ((($_FILES["image_file"]["type"] == "image/gif")
|| ($_FILES["image_file"]["type"] == "image/jpeg")
|| ($_FILES["image_file"]["type"] == "image/jpg")
|| ($_FILES["image_file"]["type"] == "image/pjpeg")
|| ($_FILES["image_file"]["type"] == "image/x-png")
|| ($_FILES["image_file"]["type"] == "image/png"))
//&& ($_FILES["image_file"]["size"] < $size)
&& in_array($extension, $allowedExts))
{
if ($_FILES["image_file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["image_file"]["error"] . "<br>";
}
else
{
$generate_random_number = rand(1,1000);
$random_image_name = $generate_random_number.$_FILES["image_file"]["name"];
if (file_exists($upload_dir_path.$random_image_name))
{
//echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["image_file"]["tmp_name"],
$upload_dir_path.$random_image_name);
}
}
}
else
{print_r($_FILES);
echo "Invalid file";
}
}
运行以下是输出:
Array ( [image_file] => Array ( [name] => Chambers_block_study.JPG [type] => image/jpeg [tmp_name] => /tmp/phpghmfM2 [error] => 0 [size] => 2656165 ) )
无效文件
请帮忙。谢谢!