-4

I use image file from other site.

<img src="//othersite.url/xxx.jpg">

But it's often unvisible. Because Http status is 404 ,301, etc.

How can I check the image can be visible?

lightwill
  • 1
  • 1

2 Answers2

0

In php you can check it if file exist ..

<?php
$imageurl=//othersite.url/xxx.jpg;
if(file_exists($imageurl)
  echo "Yes";
else
  echo "No";
?>
Rohit Kumar
  • 1,948
  • 1
  • 11
  • 16
0

Use onload and onerror event handlers.

<img src="//othersite.url/xxx.jpg" onerror="alert('error')"  onload="alert('image loaded')" >
iimos
  • 4,767
  • 2
  • 33
  • 35