Scripts
File_exists_external
Titel zegt eigenlijk al alles. Deze kleine snippet kijkt of een extern bestand bestaat en gooit a.d.h.v. het wel of niet bestaan true of false terug.
fileexistsexternal
[code]<?php
function file_exists_external($url)
{
$headers = get_headers($url);
if(!$headers)
{
return FALSE; // Failure
}
else
{
switch($headers[0])
{
case 'HTTP/1.0 200 OK':
case 'HTTP/1.1 200 OK':
return TRUE; // Found
break;
default:
return FALSE; // Else, nja, failure
break;
}
}
}
// Usage:
# Will give: Not found! :
echo (file_exists_external('http://www.yadayadayada.com/whatever.png')) ? 'Found!' : 'Not found!';
# Will give: Found!
echo (file_exists_external('http://www.google.nl/intl/nl_nl/images/logo.gif')) ? 'Found!' : 'Not found!';
/* End of file file_exists_external.php */ [/code]
Reacties
0