tags:

views:

28

answers:

2

hey guys, i'm setting a path variable with a query-string. what's the easiest way to check if 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's the best method to do that? thank you

+1  A: 

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
}
Robert Greiner