I need to check if a particular file exists on a remote server. Using is_file()
and file_exists()
doesn't work. Any ideas how to do this quickly and easily?
The file_exists() function in PHP, is used to check if a file or directory exists on the server. But the file_exists() function will not usable if you want to check the file existence on the remote server. The fopen() function is the easiest solution to check if a file URL exists on a remote server using PHP.
The file_exists() function checks whether a file or directory exists.
To check for specific files use File. Exists(path) , which will return a boolean indicating wheter the file at path exists.
The file_exists() function in PHP is an inbuilt function which is used to check whether a file or directory exists or not. The path of the file or directory you want to check is passed as a parameter to the file_exists() function which returns True on success and False on failure.
You don't need CURL for that... Too much overhead for just wanting to check if a file exists or not...
Use PHP's get_header.
$headers=get_headers($url);
Then check if $result[0] contains 200 OK (which means the file is there)
A function to check if a URL works could be this:
function UR_exists($url){ $headers=get_headers($url); return stripos($headers[0],"200 OK")?true:false; } /* You can test a URL like this (sample) */ if(UR_exists("http://www.amazingjokes.com/")) echo "This page exists"; else echo "This page does not exist";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With