file_exists
should validate that the file exists, not just that the path to the file exists.
If you're having problems you might try including the document root in your path.
题
I have a list of txt file names and paths in a SQL db. I have a directory that contains only a few files (a lot of the links are bad links). I'm using:
$filename = '/path/somename.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
to check for the file, but I'm noticing that it's always coming back as if the file is there. Is there a better alternative for this function for what I'm trying to do, or am I doing something else wrong. Thank you in advance!
解决方案
file_exists
should validate that the file exists, not just that the path to the file exists.
If you're having problems you might try including the document root in your path.
其他提示
try this :
$filename = dirname(__FILE__)."/path/somename.txt";
echo file_exists($filename) ? "The file $filename exists" : "The file $filename does not exist";