缩略图生成在服务器上不起作用-PHP库

缩略图生成在服务器上不起作用-PHP库,php,centos,php-gd,Php,Centos,Php Gd,这在本地主机上运行得很好,但在我的服务器上不起作用,有人能告诉我为什么吗?我在Centos 5设备上安装了php gd php-gd-5.1.6-32.el5.x86_64 我完全不知道为什么它不能在服务器上工作,所以,如果有人有任何想法 这是代码 <?php if (isset($_GET['img'])){ // make thumbnail if(file_exists($_GET['img'])){ ignore_user_abort(tr

这在本地主机上运行得很好,但在我的服务器上不起作用,有人能告诉我为什么吗?我在Centos 5设备上安装了php gd php-gd-5.1.6-32.el5.x86_64

我完全不知道为什么它不能在服务器上工作,所以,如果有人有任何想法

这是代码

    <?php

if (isset($_GET['img'])){
    // make thumbnail
    if(file_exists($_GET['img'])){
        ignore_user_abort(true);
        set_time_limit(120);
        ini_set('memory_limit', '512M');

        $src_size = getimagesize($_GET['img']);

        if($src_size === false){
            die('Thats not an image!');
        }

        $thumb_width    = 250;
        $thumb_height   = 200;

        if($src_size['mime'] === 'image/jpeg'){
            $src = imagecreatefromjpeg($_GET['img']);
        }else if($src_size['mime'] === 'image/png'){
            $src = imagecreatefrompng($_GET['img']);
        }else if($src_size['mime'] === 'image/gif'){
            $src = imagecreatefromgif($_GET['img']);
        }

        $src_aspect = round(($src_size[0] / $src_size[1]), 1);
        $thumb_aspect = round(($thumb_width / $thumb_height), 1);

        if($src_aspect < $thumb_aspect){
            //higher
            $new_size = array($thumb_width,($thumb_width / $src_size[0]) * $src_size[1]);
            $src_pos = array(0,(($new_size[1] - $thumb_height) * ($src_size[1] / $new_size[1])) / 2);
        }else if ($src_aspect > $thumb_aspect){
            //wider.
            $new_size = array(($thumb_width / $src_size[1]) * $src_size[0],$thumb_height);
            $src_pos = array(($new_size[0] - $thumb_width) / 2, 0);
        }else{
            // same shape
            $new_size = array($thumb_width, $thumb_height);
            $src_pos = array(0, 0);
        }

        if($new_size[0] < 1) $new_size[0] = 1;
        if($new_size[1] < 1) $new_size[0] = 1;

        $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
        imagecopyresampled($thumb, $src, 0, 0, $src_pos[0], $src_pos[1], $new_size[0], $new_size[1], $src_size[0], $src_size[1]);

        if($src_size['mime'] === 'image/jpeg'){
            imagejpeg($thumb, "thumbs/{$_GET['img']}");
        }else if($src_size['mime'] === 'image/png'){
            imagepng($thumb, "thumbs/{$_GET['img']}");
        }else if($src_size['mime'] === 'image/gif'){
            imagegif($thumb, "thumbs/{$_GET['img']}");
        }

        header("Location: thumbs/{$_GET['img']}");
    }   
    die();
}

if (is_dir('./thumbs') === false){
    mkdir('./thumbs', 0744);
}

$images = glob('*.{jpg,jpeg,png,gif}', GLOB_BRACE);

?>
<!DOCTYPE>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <div>
            <?php

            foreach($images as $image){
                if(file_exists("./thumbs/{$image}")){
                    echo "<a href=\"{$image}\" target=\"_blank\"><img style='border: 4px solid black;' src=\"thumbs/{$image}\" alt=\"{$image}\" /></a>";
                }else{
                    echo "<a href=\"{$image}\" target=\"_blank\"><img style='border: 4px solid black;' src=\"?img={$image}\" alt=\"{$image}\" /></a>";
                }
            }

            ?>
        </div>
    </body>
</html>

您确定服务器上也安装了gd库吗?

据我所知,我觉得可能没有什么原因

未安装GD库-您可以在此处找到安装说明。 这可能是一个权限问题。您需要在特定目录中具有写入权限才能创建缩略图。 PHP执行没有足够的内存。您可以尝试使用下面的代码手动设置内存限制。把这个放在函数的开头。ini_设置“内存限制”,-1;并在函数结束时重置它,然后返回结果。ini_恢复“内存限制”;
您检查了该目录的权限了吗?您能详细说明运行脚本时收到的错误吗?我想可能是这样的,我现在正在研究它。:。。。因为你是新来的。。。我恳请你接受正确的答案。。。这会提高我的声誉,也会提高你的。。谢谢