我发现这段代码可以在 javascript 上获取图像大小:
function getImgSize(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
var height = newImg.height;
var width = newImg.width;
alert ('The image size is '+width+'*'+height);
}
它工作得很好,但我需要获得受保护图像的大小;为了访问图像,我使用页面 image.php?id=IMAGE_ID,它可以工作,因为在这个页面中我检查了权限并将图像发回。但是当我把这个链接放在javascript函数上时,为了得到它的大小,它就不起作用了。任何帮助(如果我放置图像的直接链接,它也不起作用,因为它在 .htaccess 文件中被阻止)?
包含图像的文件夹还包含一个 .htaccess 文件,它可以访问所有内容。为了获取图像,我使用了这个 PHP 页面:
图片.php:
//check if the user has permission
//if not, show a image with the text 'no permission'
//if it's ok
$filename = "images\\fotos\\" . $imgl;
$image = imagecreatefromjpeg($filename);
header('Content-type: image/jpeg');
imagejpeg($image, null, 100);
imagedestroy($image);