PHP 调整大小脚本在新服务器/域上不起作用


PHP Resize Script not working on new server/domain

我有调整大小.php脚本在我以前的服务器/域上运行,当您转到它时 这里 你可以看到除以零错误。但!如果您在新域/服务器上转到相同的脚本,这是一个没有错误的空白页面,这让我相信有些事情没有像应该的那样发生。我是一个快速学习者,但有点像PHP菜鸟。任何关于简单地调整 php 图像数组大小并显示它们的建议,我将不胜感激任何帮助。

<?php session_start();header("Pragma: public");header("Cache-Control: max-age = 604800");
header("Expires: ".gmdate("D, d M Y H:i:s", time() + 604800)." GMT");
function thumbnail($image, $width, $height) {
    if($image[0] != "/") { // Decide where to look for the image if a full path is not given
        if(!isset($_SERVER["HTTP_REFERER"])) { // Try to find image if accessed directly from this script in a browser
            $image = $_SERVER["DOCUMENT_ROOT"].implode("/", (explode('/', $_SERVER["PHP_SELF"], -1)))."/".$image;
        } else {
            $image = implode("/", (explode('/', $_SERVER["HTTP_REFERER"], -1)))."/".$image;
        }
    } else {
        $image = $_SERVER["DOCUMENT_ROOT"].$image;
    }
    $image_properties = getimagesize($image);
    $image_width = $image_properties[0];
    $image_height = $image_properties[1];
    $image_ratio = $image_width / $image_height;
    $type = $image_properties["mime"];
    if(!$width && !$height) {
        $width = $image_width;
        $height = $image_height;
    }
    if(!$width) {
        $width = round($height * $image_ratio);
    }
    if(!$height) {
        $height = round($width / $image_ratio);
    }
    if($type == "image/jpeg") {
        header('Content-type: image/jpeg');
        $thumb = imagecreatefromjpeg($image);
    } elseif($type == "image/png") {
        header('Content-type: image/png');
        $thumb = imagecreatefrompng($image);
    } else {
        return false;
    }
    $temp_image = imagecreatetruecolor($width, $height);
    imagecopyresampled($temp_image, $thumb, 0, 0, 0, 0, $width, $height, $image_width, $image_height);
    $thumbnail = imagecreatetruecolor($width, $height);
    imagecopyresampled($thumbnail, $temp_image, 0, 0, 0, 0, $width, $height, $width, $height);
    if($type == "image/jpeg") {
        imagejpeg($thumbnail);
    } else {
        imagepng($thumbnail);
    }
    imagedestroy($temp_image);
    imagedestroy($thumbnail);
}
if(isset($_GET["h"])) { $h = $_GET["h"]; } else { $h = 0; }
if(isset($_GET["w"])) { $w = $_GET["w"]; } else { $w = 0; }
thumbnail($_GET["img"], $w, $h);
?>

我会确保打开错误进行调试,检查是否使用 phpinfo() 启用了 GD 库,并确保创建拇指的目录是可写的。