N
N
NoKioO2018-03-15 18:49:23
linux
NoKioO, 2018-03-15 18:49:23

Problem getting image content - PHP Warning: getimagesize?

Hello, I
have a clean virtual machine with Ubuntu 16 and an image like: https://img1.goodfon.ru/wallpaper/big/1/ca/foto-ma... Image uploader
always returns warning:
PHP Warning: getimagesize( https: //img1.goodfon.ru/wallpaper/big/1/ca/foto-ma... failed to open stream: HTTP request failed! in Command line code on line 1
bool(false)
Can be reproduced like this:

php -r 'echo var_dump(getimagesize("https://img1.goodfon.ru/wallpaper/big/1/ca/foto-makro-kartinka-zelenye.jpg"));'

At the same time, curl returns the image without problems:
curl -v https://img1.goodfon.ru/wallpaper/big/1/ca/foto-makro-kartinka-zelenye.jpg

Help me figure it out plz.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2018-03-16
@NoKioO

<?php
$ch = curl_init("https://img1.goodfon.ru/wallpaper/big/1/ca/foto-makro-kartinka-zelenye.jpg");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_exec($ch);
curl_close($ch);

We get:
...
> GET /wallpaper/big/1/ca/foto-makro-kartinka-zelenye.jpg HTTP/1.1
Host: img1.goodfon.ru
Accept: */*
* Empty reply from server
* Connection #0 to host img1 .goodfon.ru left intact

Add one line to our code
And everything works right away.
Conclusion: The server (Nginx) gives an empty response if user-agent is not specified.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question