PHP调整大小脚本无法在新服务器/域上运行 [英] PHP Resize Script not working on new server/domain

查看:111
本文介绍了PHP调整大小脚本无法在新服务器/域上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以前的服务器/域上运行了resize.php脚本,当您访问它时,此处将显示空白页面,没有错误让我相信事情并没有像应该发生的那样发生.我是一个快速学习者,但有点PHP新手.只需调整图像的php数组大小并显示它们的任何建议,我将不胜感激.

I had the resize.php script working on my previous server/domain and when you go to it HERE you can see the division by zero error. BUT! if you go to the same script on the new domain/server HEREits a blank page with no errors which leads me to believe something is not happening like it should be. I'm a quick learner but a bit of a PHP noob. Any advice with simply resizing a php array of images and displaying them I would appreciate any help.

<?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库,并确保拇指所在的目录创建的是可写的.

I would make sure errors are turned on for debugging, check if the GD library is enabled using phpinfo(), and make sure that the directory where the thumbs are created is writable.

这篇关于PHP调整大小脚本无法在新服务器/域上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆