PHP imagecreatefromjpeg无错误,无图像

PHP imagecreatefromjpeg无错误,无图像,php,jpeg,gd,Php,Jpeg,Gd,我正在使用这个代码 <?php $sImagePath = $_GET["file"]; $iThumbnailWidth = (int)$_GET['width']; $iThumbnailHeight = (int)$_GET['height']; $iMaxWidth = (int)$_GET["maxw"]; $iMaxHeight = (int)$_GET["maxh"]; if ($iMaxWidth && $iMaxHeight) $sType = 's

我正在使用这个代码

<?php

$sImagePath = $_GET["file"];

$iThumbnailWidth = (int)$_GET['width'];
$iThumbnailHeight = (int)$_GET['height'];
$iMaxWidth = (int)$_GET["maxw"];
$iMaxHeight = (int)$_GET["maxh"];

if ($iMaxWidth && $iMaxHeight) $sType = 'scale';
else if ($iThumbnailWidth && $iThumbnailHeight) $sType = 'exact';

$img = NULL;

$sExtension = strtolower(end(explode('.', $sImagePath)));
if ($sExtension == 'jpg' || $sExtension == 'jpeg') {

    $img = @imagecreatefromjpeg($sImagePath)
        or die("Cannot create new JPEG image");

} else if ($sExtension == 'png') {

    $img = @imagecreatefrompng($sImagePath)
        or die("Cannot create new PNG image");

} else if ($sExtension == 'gif') {

    $img = @imagecreatefromgif($sImagePath)
        or die("Cannot create new GIF image");

}

if ($img) {

    $iOrigWidth = imagesx($img);
    $iOrigHeight = imagesy($img);

    if ($sType == 'scale') {

        // Get scale ratio

        $fScale = min($iMaxWidth/$iOrigWidth,
              $iMaxHeight/$iOrigHeight);

        if ($fScale < 1) {

            $iNewWidth = floor($fScale*$iOrigWidth);
            $iNewHeight = floor($fScale*$iOrigHeight);

            $tmpimg = imagecreatetruecolor($iNewWidth,
                               $iNewHeight);

            imagecopyresampled($tmpimg, $img, 0, 0, 0, 0,
            $iNewWidth, $iNewHeight, $iOrigWidth, $iOrigHeight);

            imagedestroy($img);
            $img = $tmpimg;
        }     

    } else if ($sType == "exact") {

        $fScale = max($iThumbnailWidth/$iOrigWidth,
              $iThumbnailHeight/$iOrigHeight);

        if ($fScale < 1) {

            $iNewWidth = floor($fScale*$iOrigWidth);
            $iNewHeight = floor($fScale*$iOrigHeight);

            $tmpimg = imagecreatetruecolor($iNewWidth,
                            $iNewHeight);
            $tmp2img = imagecreatetruecolor($iThumbnailWidth,
                            $iThumbnailHeight);

            imagecopyresampled($tmpimg, $img, 0, 0, 0, 0,
            $iNewWidth, $iNewHeight, $iOrigWidth, $iOrigHeight);

            if ($iNewWidth == $iThumbnailWidth) {

                $yAxis = ($iNewHeight/2)-
                    ($iThumbnailHeight/2);
                $xAxis = 0;

            } else if ($iNewHeight == $iThumbnailHeight)  {

                $yAxis = 0;
                $xAxis = ($iNewWidth/2)-
                    ($iThumbnailWidth/2);

            } 

            imagecopyresampled($tmp2img, $tmpimg, 0, 0,
                       $xAxis, $yAxis,
                       $iThumbnailWidth,
                       $iThumbnailHeight,
                       $iThumbnailWidth,
                       $iThumbnailHeight);

            imagedestroy($img);
            imagedestroy($tmpimg);
            $img = $tmp2img;
        }    

    }

    header("Content-type: image/jpeg");
    imagejpeg($img);

}

?>

imagecreatefromjpeg可以在我的八幅图像上工作,但不能在其中三幅图像上工作。它们是Photoshop save for web JPG,具有良好的权限。我没有收到错误,但是如果$img

您是否正确检查了它们的扩展名?如果您的服务器上的错误报告和显示处于关闭状态,在打开文件后立即将错误报告添加到文件顶部。我怀疑这是因为您只有一种类型的标题内容类型:image/jpeg;这对.png和.gif不起作用。您需要尝试在另一组条件中添加适当的标题。这是如果那些与其他文件相关的文件类型不是jpeg.Fred-ii-;谢谢你的回复。我只收到代码行5和6的两个通知。。。注意:未定义索引:url中的宽度注意:未定义索引:url中的高度不客气。然后,就是如何使用GET方法传递URL。您需要向我们展示一个您如何使用它的示例。