I need to check whether a file exists using the is_dir() function. However I need to check whether a file exists within a certain folder. This is what I thought the code would look like: if ($_GET['filename']) { $file = "courses/".$_GET['filename']; if (is_dir($file)){ echo "yes"; }else { echo "no"; } } else { die('must specify filename'); } PHP: this is supposed to work isn't it? I'm getting no coding errors, the script is just not detecting the file. The funny thing is that when I just enter "courses" in the $file variable, it detects a folder name 'courses' By the way, 'filename' is urlencoded $_GET from a previous script that lets the user choose the file to be displayed. Is there a different way of doing this?
is_dir() checks specifically for directories. Use file_exists() or is_file() instead. (Note that file_exists() works for directories AND files)