php: check if path exists?
I am setting a path variable with a query-string.
What is the easiest way to check i开发者_Python百科f the path (always a directory) exists or not.
if(isset($_GET['p'])) {
define(PATH, $_GET['p']);
So now I have like mydomain.com?p=files/folder/sub and everything works fine, i'm reading the contents of the folder. However, I can pass along ?p=shit/whatever and i don't get a 404 or anything like that. the system reads a folder which does not even exist.
I don't even need a 404, but just want to print('does not exist!') or anything similar.
What is the best method to do that?
file_exists: http://php.net/manual/en/function.file-exists.php
is_dir: http://php.net/manual/en/function.is-dir.php
If this is on your local machine you can use file_exists()
http://php.net/manual/en/function.file-exists.php
if (!file_exists($filename)) {
//print your error
}
精彩评论