-1

I am working on a site which is fetching images from a cdn server that has allow_url_fopen in turned off means allow_url_fopen=off.

The problem is that before showing the image in main site we have to check the existence of image in cdn server. If image exists then we will show it otherwise not.

file_exists and file_get_contents will not work as they require allow_url_fopen=on.

Is there any other way to do it???

Any help will be appreciated.

Thanks

  • [like mentioned many times before](http://stackoverflow.com/search?q=allow_url_fopen+alternative), the alternative would be to check if cURL is available. And if it isnt, you have to try any of the solutions given in http://stackoverflow.com/questions/3880628/how-to-scrape-websites-when-curl-and-allow-url-fopen-is-disabled – Gordon Feb 09 '12 at 13:39
  • Do you have cURL access? – WWW Feb 09 '12 at 13:40
  • possible duplicate of [PHP, need help using cURL as allow_url_fopen is disabled](http://stackoverflow.com/questions/9071895/php-need-help-using-curl-as-allow-url-fopen-is-disabled) – Gordon Feb 09 '12 at 13:44

2 Answers2

0

You can use cUrl:

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if(empty($result)){die('No image');}
Narek
  • 3,813
  • 4
  • 42
  • 58
  • 1
    This is not a proper way , because curl result may contain http headers to, so better check the status code of http header – Akhil Thayyil Feb 09 '12 at 13:46
  • Never see what `curl_exec` returns headers. As I know for headers you need to add `curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); ` – Narek Feb 09 '12 at 14:05
0

You can use the CURL library to get the file via HTTP method. If that is used , if the file exists, the status code will be success otherwise not found status code will be returned. Another options is to use the socket library function like fsockopen to connect to that server and access the files via FTP if that is enabled.

Go through the examples given http://php.net/manual/en/function.fsockopen.php http://php.net/manual/en/function.fsockopen.php

Akhil Thayyil
  • 9,263
  • 6
  • 34
  • 48