how to check if a file exists in a external server using PHP

If you are doing a script to check if a file exists you can use the function

file_exists($link)

 

But if you use this function with a file of a external server the function don't work for security reasons.

To chek if a file of a external server exists you can use this function:

//the file you want to check
$url='http://www.fotoefectos.com/mrbean.jpg';
$contents = file_get_contents("$url");

if (strlen($contents))
{
echo "yes"; // yes it does exist
}
else
{
echo "no"; // no exist!!
}

An that's all!!

 

Formato: 
htm