Dewayne
Dewayne

Reputation: 3742

PHP Warning when attempting to use stat() or filemtime()

I am attempting to get the last modified time of a file that definately does exist: /document_root/myfile.pdf -rwxr-xr-x 1 11018 11008 198621 Nov 26 2007 myfile.pdf

When i run the following statement (through PHP CLI as root): filemtime('/document_root/myfile.pdf');

I get errors: Warning: stat(): Stat failed for /document_root/myfile.pdf (errno=2 - No such file or directory)

Upvotes: 0

Views: 3555

Answers (3)

Jon Cram
Jon Cram

Reputation: 17309

You're getting the file path wrong or you don't have permission to stat the relevant file.

Wrong file path?

filemtime('/document_root/myfile.pdf');

Right file path?

filemtime($_SERVER['DOCUMENT_ROOT'].'/myfile.pdf');

Check the file's permissions: can the file be read by the user under which PHP is running?

Upvotes: 1

apinstein
apinstein

Reputation: 5223

Are you sure you've got the right path?

/document_root/myfile.pdf

Looks like an absolute path, but I doubt your "document_root" is in the root filesystem.

If that's not it, also make sure that the apache user has read access to the file itself, but also r+x access to all directories leading up to the file path.

Upvotes: 0

da5id
da5id

Reputation: 9136

You're not doing something like running this from within a function where you haven't passed through a value for document_root?

Upvotes: 0

Related Questions