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
Post a Comment