php check if remote image cant be displayed -


i have script gets images external website , display on mine. need show different image if external image 404 or can't displayed. tried various approaches couldnt find works :(

this example of image cant displayed on remote server (it show text error instead of displaying image) http://image.spreadshirtmedia.com/image-server/v1/compositions/1112876576765766798/views/1,width=1000,height=1000,appearanceid=95/

and here's code

$path = "http://image.spreadshirtmedia.com/image-server/v1/compositions/111286798/views/1,width=1000,height=1000,appearanceid=95/t.jpg";  // load requested image $image = imagecreatefromstring(file_get_contents($path.'?'.mt_rand()));  // send image header('content-type: image/png');   function get_http_response_code($path) {     $headers = get_headers($path);     return substr($headers[0], 9, 3); } if(get_http_response_code($path) != "404"){     imagepng($image); }else{     imagepng("notfound.png"); } 

i can instruct curl solve problem:

code example:

$curlini = curl_init("http://image.spreadshirtmedia.com/image-server/v1/compositions/111286798/views/1,width=1000,height=1000,appearanceid=95/t.jpg");  curl_setopt($curlini, curlopt_nobody, true); curl_exec($curlini); $returncode = curl_getinfo($curlini, curlinfo_http_code); // $returncode >= 400 -> not found, $returncode = 200, found. curl_close($curlini); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -