You will run into issues with your way of programming this if the directory you're talking about isn't the current directory ... $file will only contain the file/path, not the FULL path to the file/dir you're checking - use something like this instead:
Enjoy,