tags:

views:

306

answers:

3

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)

A: 

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

da5id
A: 

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.

apinstein
+1  A: 

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?

Jon Cram