1

我正在使用这个功能:

function image_resizer($max_width,$max_height,$img_path) {
    list($width, $height) = getimagesize($img_path);
    if (($width > $max_width) or ($height > $max_height)) {
        $ratioh = $max_height/$height;
        $ratiow = $max_width/$width;
        $ratio = min($ratioh, $ratiow);

        $width = intval($ratio*$width);
        $height = intval($ratio*$height);
    }
    return 'width="' . $width . '" height="' . $height . '"';
}

...使用此代码调用(定义位于此处粘贴的另一个文件中以供说明):

define("SITE_URI", "http://dev.projectname.co.uk/");
define("PRODUCT_IMAGES_URI", "images/collection/");
<?php echo image_resizer(280, 375, SITE_URI . PRODUCT_IMAGES_URI . $display_image); ?> alt="<?php echo $display_image; ?>

...其中 $display_image 来自数据库(成功)。并得到以下错误:

警告:getimagesize(http://dev.projectname.co.uk/images/collection/filename.jpg)[function.getimagesize]:打开流失败:HTTP请求失败!HTTP/1.1 401 授权需要在 /var/www/projectname.co.uk/dev/admin/includes/functions_admin.php 第 59 行 width="" height="" alt="filename.jpg" />

我正在使用 getimagesize() 从最初授予服务器上 www-data 用户权限的文件夹中获取图像的大小,然后当我再次收到错误时,我只是 chmod 777 到图像文件夹。我现在不知所措。

4

2 回答 2

4

答案很简单,我试图使用 url 访问服务器上的文件夹,我需要服务器上文件夹的绝对路径。这已经在本地机器上运行,并通过裂缝溜到了开发服务器。

于 2010-11-23T22:13:42.783 回答
1

问题不在于getimagesize(),问题在于您试图从受密码保护的 URL 中检索它。要么将用户名和密码作为 URL 的一部分传递,要么以其他方式获取。

于 2010-11-23T22:14:55.913 回答