I create a plugin for WordPress that requires two files to be exists in order to operate normaly.
The first file is defined as a file system path and the second file is defined as a URL.
Let's say the first file is that:
/home/my_site/public_html/some_folder/required_file.php
and the second file is that:
http://www.my_site.com/some_folder/required_url_file.php
Note that both files are not the same file into the file system. The required_file.php has other content than the required_url_file.php and they act absolutly diferent
Any idea on how to validate the existance of both files ?
As for validating the URL, none of these answers are considering the correct, WordPress way to carry out this task.
For this task
wp_remote_head()
should be used.Here's an article I've written about How To Check Whether an External URL Exists with WordPress’ HTTP API. Check it out and figure out how it works.
If you have PECL
http_head
function available, you could check if it returns status code 200 for the remote file.To check if you can access the local file, could use
file_exists
, but this does not grant that you will be able to access that file. To check if you can read that file, useis_readable
.You can check both:
To check if a file exists, use the file_exists method.