PHP getimagesize () not working

<?php $URL="http://cor-forum.de/forum/images/smilies/zombie.png"; list($width, $height) = getimagesize($URL); echo 'width: '.$width.'<br> height: '.$height; ?> 

The result is the following result:

 width: height: 

EDIT and I get the following warning:

Warning: getimagesize ( http://cor-forum.de/forum/images/smilies/zombie.png ): Could not open stream: HTTP request failed! HTTP / 1.1 403 Forbidden in / home / webpages / lima -city / regnum-forum / html / DATEIEN / scheisstest.php on line 6

- whereas it displays the correct values ​​if I use another image, for example

 $URL='http://getfavicon.appspot.com/http://google.com?defaulticon=1pxgif'; 

EDIT: I would like to include the inclusion of external images in the forum, but first I want to check their size. So what can I do to get the size of the image whose server is β€œblocking me”?

EDIT: allow_url_fopen is set to ON, yes.

+3
php
source share
3 answers

Faking the HTTP link field seems to work on this:

 <?php function getimgsize($url, $referer = '') { $headers = array( 'Range: bytes=0-32768' ); /* Hint: you could extract the referer from the url */ if (!empty($referer)) array_push($headers, 'Referer: '.$referer); $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); curl_close($curl); $image = imagecreatefromstring($data); $return = array(imagesx($image), imagesy($image)); imagedestroy($image); return $return; } list($width, $heigth) = getimgsize('http://cor-forum.de/forum/images/smilies/zombie.png', 'http://cor-forum.de/forum/'); echo $width.' x '.$heigth; ?> 

Source code

+6
source share

It looks like you have problems with the specified URL, you can try the code below I did nothing, just changed the URL,

 URL = "http://forums.phpfreaks.com/uploads/profile/photo-thumb-68615.jpg"; list($width, $height) = getimagesize($URL); echo 'width: ' . $width . '<br>height: ' . $height; 
-one
source share

set PHP memory limit to 256 MB to fix it

-2
source share

All Articles