I'm using this function:
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 . '"';
}
...called with this code (the defines are in another file pasted here for illustration):
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; ?>
...where $display_image is coming from the DB (successfully). And getting the following error:
Warning: getimagesize(http://dev.projectname.co.uk/images/collection/filename.jpg) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /var/www/projectname.co.uk/dev/admin/includes/functions_admin.php on line 59 width="" height="" alt="filename.jpg" />
I'm using getimagesize() to get the size of an image from a folder that I initially gave rights to the www-d开发者_如何学Pythonata user on the server, then when I got the error again I just chmod 777 to the image folder. I'm now at a loss.
The answer was simple, I was attempting to use a url to access a folder on the server, I needed the absolute path to the folder on the server instead. This had worked on the local machine and slipped through the cracks to the development server.
The problem isn't getimagesize()
, the problem is that you're trying to retrieve it from a password-protected URL. Either pass the username and password as part of the URL, or get it some other way.
精彩评论