Php file_get_contents () stuck in image upload

As mentioned above, the php file_get_contents () function or even the fopen () / fread () combination flock and the wait time when trying to read this simple image URL:

http://pics.redblue.de/artikelid/GR/1140436/fee_786_587_png 

but the same image is easily downloaded by browsers, what is the catch?

Edition:

as pointed out in the comments, I show the function that I used to get the data:

 function customRead($url) { $contents = ''; $handle = fopen($url, "rb"); $dex = 0; while ( !feof($handle) ) { if ( $dex++ > 100 ) break; $contents .= fread($handle, 2048); } fclose($handle); echo "\nbreaking due to too many calls...\n"; return $contents; } 

I also tried simply:

 echo file_get_contents('http://pics.redblue.de/artikelid/GR/1140436/fee_786_587_png'); 

Both give the same problem

Edition:

As suggested in the comment, I used curl:

 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11'); $res = curl_exec($ch); $rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch) ; echo "\n\n\n[DATA:"; echo $res; echo "]\n\n\n[CODE:"; print_r($rescode); echo "]\n\n\n[ERROR:"; echo curl_error($ch); echo "]\n\n\n"; 

this is the result:

 [DATA:] [CODE:0] [ERROR:] 
+5
source share
1 answer

If you do not receive deleted data using file_get_contents , you can try it with cURL, as it can provide error messages on curl_error . If you get nothing, not even any errors, then something on your server blocks outgoing connections. You might even want to try curl through SSH. I'm not sure if that matters, but worth a try. If you do not receive anything, you might want to contact the server administrator (if this is not the case) or the provider.

+1
source

Source: https://habr.com/ru/post/1242194/


All Articles