PHP to check file exist on external server using file_get_contents() -


checking file exists on external server using file_get_contents() method, method work properly?

$url_file = "http://website.com/dir/filename.php"; $contents = file_get_contents($url_file);  if($contents){ echo "file exists!"; } else { echo "file doesn't exists!"; } 

i think best method me using script:

$file = "http://website.com/dir/filename.php"; $file_headers = get_headers($file); 

if file not exists output $file_headers[0] is: http/1.0 404 not found or http/1.1 404 not found

use strpos method check 404 string if file doesn't exists:

if(strpos($file_headers[0], '404') !== false){ echo "file doesn't exists!"; } else { echo "file exists!"; } 

thanks :)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -