I'm working on a script to display all the files (and some info about them) from a specific directory. The script is able to see and display the files in this directory, but stat(), filesize(), and filetype(), all return errors like:
Warning: filesize(): Stat failed for strde895b.jpg (errno=2 - No such file or directory) in /opt2/home3/amdesign/public_html/library/index.php on line 117
Warning: filetype(): Lstat failed for (null) (errno=2 - No such file or directory) in /opt2/home3/amdesign/public_html/library/index.php on line 118
Why does it list the files but not their stats? If I put my PHP script in the same directory ( dir(".") ) as the files, it works just fine. But when I put the script in the directory above and try to display the contents of the subdirectory that contains the files ( dir("files/") ) I get the file names with the above errors. Here's a snippet of the code I'm using, with the variety of directory paths I've tried:
$d = dir("."); // THIS WORKS
$d = dir("./files/"); //DOESN'T WORK
$d = dir("files/"); //DOESN'T WORK
$d = dir("/absolute/complete/path/to/files/"); //DOESN'T WORK
while ($file = $d->read()) {
// Get file attributes.
$size = filesize($file);
$type = filetype($file);
$modified = stat("$file");
echo $filename;
echo $size;
echo $type;
}
Any ideas? I'm totally baffled, though it's probably something silly I've overlooked. Thanks in advance.
IZA