English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

what is the php code or function to check if any perticular file exists on a website or not

eg.

http://mysite.com/my_image.gif
if this image present then return yes otherwise return no

2007-07-26 22:17:03 · 2 answers · asked by Mohammad Shahid 1 in Computers & Internet Programming & Design

I am using PHP Version 4.3.10 and file_exists function can not be used with URL wrappers.

2007-07-26 23:01:54 · update #1

2 answers

This will search for the file. If the file does not exist, you will get a 404 header so that is how it works out if the file exists or not:

$file = 'http://mysite.com/my_image.gif';
$file_headers = @get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = false;
}
else {
$exists = true;
}

2007-07-28 06:37:54 · answer #1 · answered by E.M.Bed 5 · 0 0

That will be
file_exists("test.txt");

2007-07-27 05:24:32 · answer #2 · answered by AnalProgrammer 7 · 0 0

fedest.com, questions and answers