PHP:无法识别图像类型


PHP: Image type does not get recognized

我有一个网站运行在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吗?

        <?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

它正在工作。。。