我發現這個代碼,以獲得對JavaScript的圖像尺寸:從PHP的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頁面:
Image.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);
您必須允許瀏覽器中打開'imgSrc',否則JS不能得到什麼,同樣,在真實服務器,你必須要考慮延遲以及 – 2012-02-18 11:30:44
「受保護「如何?通過密碼對話框? – 2012-02-18 11:30:52
它可能會檢查所需的cookie或會話變量。 – 2012-02-18 11:33:31