Search code examples
phpapachefopengetimagesize

getimagesize / fopen connection refused


I am trying to get the size from an remote image with the native php function getimagesize from an absolute URL. I am using PHP 7.3, here is the code:

$fichier = 'http://mydomain/images/image.jpg';
$size = getimagesize($fichier);
var_dump($size);

And the code return :

PHP Warning: getimagesize(http://mydomain/images/image.jpg): failed to open stream: Connection refused in ...

And with fopen, same problem:

PHP Warning: fopen(http://mydomain/images/image.jpg): failed to open stream: Connection refused 

And when I am trying the same URL from an other server, it is working.

Also, if I am trying to get infos from an other image and from an other domain but on the same server, it is not working also.

allow_url_fopen is enabled. I think that it should come from Apache conf, but not sure... Anybody has an idea ? Thanks !


Solution

  • Finally, the problem is coming from the network. Apache could not resolve his own public domain name. So to correct the problem, I just had " 127.0.0.1 mydomain" in the hosts file, and the problem was solved. Hope it can help !