-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

3

2 Answers 2

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');} 
Sign up to request clarification or add additional context in comments.

2 Comments

This is not a proper way , because curl result may contain http headers to, so better check the status code of http header
Never see what curl_exec returns headers. As I know for headers you need to add curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.