fileexistsexternal
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?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]
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]