OK this has to be a noob question but it's got me stumped. I'm working with the file_exists() function. (http://w3schools.com/php/func_filesystem_file_exists.asp) Here's my issue: INPUT: echo file_exists("test.txt"); 1. test.txt does not exist: OUTPUT: (nothing) 2. test.txt exists: OUTPUT: 1 So this is why this is a noob question: My issue is, I need to test if a file exists that's not in the same directory as the script containing the function file_exists(). So I've tried 3. echo file_exists("http://www.example.com/test.txt") OUTPUT: (nothing) 4. echo file_exists("/test.txt") OUTPUT: (nothing) How do I check if test.txt exists if it's in a different directory than the script containing the function?
file_exists() just doesn't work with HTTP addresses. It only supports filesystem paths (and FTP, if you're using PHP5.)
file_exist can be checked only using directories. if u have www folder and a subfolder called uploads .. u want to check a file 1.jpg exist in that folder u have ur file in www then u want to write the code as... if(file_exists("uploads/1.jpg")) echo "file is present"; else echo "false"; u can also use glob function for this purpose. first take all the files present in a folder and then check with the name...
That would be a file called "test.php" in the root directory of the system, is that what you wanted? It's likely that your PHP script doesn't have the proper permissions to access that directory.
I need to run this test with multiple directories, since both files to be checked for existence and also the scripts checking for exisitence will be in various directories and also the scripts checking for the files will be in various directories. So counting back and saying something like "../../../../folder/test.php" is not an option.
Problem seems to be solved. Here's what worked: if (file_exists($_SERVER['DOCUMENT_ROOT']."/folder/test.txt") echo "file exists"; PHP: