我在服务器上运行了一个 PHP 5.1.6.1。
当我尝试上传图片时,我收到不支持图片类型的错误消息,尽管它肯定是允许的图片类型的一方。这是我的代码:
$imgUrl = $_POST['imgUrl'];
$imgInitW = $_POST['imgInitW'];
$imgInitH = $_POST['imgInitH'];
$imgW = $_POST['imgW'];
$imgH = $_POST['imgH'];
$imgY1 = $_POST['imgY1'];
$imgX1 = $_POST['imgX1'];
$cropW = $_POST['cropW'];
$cropH = $_POST['cropH'];
$jpeg_quality = 100;
$output_filename = "../uploads/users/croppedImg_".rand();
$what = getimagesize($imgUrl);
switch(strtolower($what['mime']))
{
case 'image/png':
$img_r = imagecreatefrompng($imgUrl);
$source_image = imagecreatefrompng($imgUrl);
$type = '.png';
break;
case 'image/jpeg':
$img_r = imagecreatefromjpeg($imgUrl);
$source_image = imagecreatefromjpeg($imgUrl);
$type = '.jpeg';
break;
case 'image/gif':
$img_r = imagecreatefromgif($imgUrl);
$source_image = imagecreatefromgif($imgUrl);
$type = '.gif';
break;
default: die('image type not supported');
}
例如,如果我想上传jpg文件,我会收到消息"不支持图像类型"。
令人惊讶的是:使用PHP 5.3.29在不同的服务器上运行网站不会产生任何问题,这里图像上传工作完美。
PHP无法正确识别图像类型的原因是什么?是因为PHP版本是5.1.6.1吗?
答案 0 :(得分:-1)
<?php
$imgUrl = $_GET['imgUrl'];
$jpeg_quality = 100;
$what = getimagesize($imgUrl);
switch(strtolower($what['mime']))
{
case 'image/png':
$img_r = imagecreatefrompng($imgUrl);
$source_image = imagecreatefrompng($imgUrl);
$type = '.png';
echo "string";
break;
case 'image/jpeg':
$img_r = imagecreatefromjpeg($imgUrl);
$source_image = imagecreatefromjpeg($imgUrl);
$type = '.jpeg';
echo "string";
break;
case 'image/gif':
$img_r = imagecreatefromgif($imgUrl);
$source_image = imagecreatefromgif($imgUrl);
$type = '.gif';
echo "string";
break;
default: die('image type not supported');
}
?>
转到:http:// localhoost~ / test / image.php?imgUrl = http://upload.wikimedia.org/wikipedia/commons/2/2a/Junonia_lemonias_DSF_upper_by_Kadavoor.JPG
它正在运作......