Page 1 of 2

[function.filemtime]: stat failed for *FILE* error

Posted: Sun Apr 16, 2006 8:25 am
by ozzy
Im getting the following error message:

Code: Select all

filemtime() [function.filemtime]: stat failed for *FILENAME* on line 45
December 31 1969 19:00:00.
This occurs when i use the filemtime() function in my page:

Code: Select all

. date ("F d Y H:i:s.", filemtime($filename))
I tryed searching google for awnsers, but all it is returning is sites which are suffering from this error. Ehat is the meaning behind this error message, and how do i reslove it?

Thanks in advance.

Posted: Sun Apr 16, 2006 9:05 am
by Ambush Commander
I believe it's unable to determine the last modified time from the file for what ever reason (maybe corruption). You can try muting the error like this:

Code: Select all

date ("F d Y H:i:s.", @filemtime($filename))
But it will still give you this bogus date (December 31 1969 19:00:00.) Alternatively... you can do this.

Code: Select all

function smart_filemtime($filename) {
  $time = @filemtime($filename);
  if ($time) return $time;
  else return time();
}

Posted: Sun Apr 16, 2006 9:08 am
by Oren
What is the last modification time of the file?

Posted: Sun Apr 16, 2006 9:22 am
by John Cartwright
Oren wrote:What is the last modification time of the file?
the time the file was last modified :?

--

Have you tried checking for the files exisance before running it through filemtime?

Posted: Sun Apr 16, 2006 9:31 am
by ozzy
Ambush Commander wrote:I believe it's unable to determine the last modified time from the file for what ever reason (maybe corruption). You can try muting the error like this:

Code: Select all

date ("F d Y H:i:s.", @filemtime($filename))
But it will still give you this bogus date (December 31 1969 19:00:00.) Alternatively... you can do this.

Code: Select all

function smart_filemtime($filename) {
  $time = @filemtime($filename);
  if ($time) return $time;
  else return time();
}
Its seems to disable the error message being displayed but it dosnt reslove the error. :(

Posted: Sun Apr 16, 2006 9:32 am
by Oren
Jcart wrote:
Oren wrote:What is the last modification time of the file?
the time the file was last modified :?

--

Have you tried checking for the files exisance before running it through filemtime?
:? :? :? :? :? :? :? I know what it is!!!!! I'm asking for the last modification time of the file he's working with!

Posted: Sun Apr 16, 2006 9:34 am
by John Cartwright
Oren wrote:
Jcart wrote:
Oren wrote:What is the last modification time of the file?
the time the file was last modified :?

--

Have you tried checking for the files exisance before running it through filemtime?
:? :? :? :? :? :? :? I know what it is!!!!! I'm asking for the last modification time of the file he's working with!
Ah, well the OP told us December 31 1969 19:00:00 is the resulting from filemtime, so I was a bit confused by your post.

Either way, to repeat my last post ozzy, did you run the file through file_exists() first to assure your paths are set correctly?

Posted: Sun Apr 16, 2006 9:48 am
by ozzy
its not that the files dosnt exist, i know this becouse the are being returned in the same script using glob or opendir, its just that the times arent being returned. Even so, i tryed file_exists and im still getting the same problem; file being returned successfully, but not the time. :)

Posted: Sun Apr 16, 2006 9:52 am
by Oren
Jcart: You still get me wrong... I saw what the returned date was. I'm asking what is the real modification date like when you Right Click->Prpperties and then you check under "Last modified: [date_here]" (on Windows).

Posted: Sun Apr 16, 2006 9:53 am
by feyd
What's $filename in this particular case?

Posted: Sun Apr 16, 2006 9:57 am
by Oren
Try to use the filectime() function and tell us whether it works or not (just as a test not instead of filemtime()).

Posted: Sun Apr 16, 2006 9:58 am
by ozzy
What's $filename in this particular case?
Filename:

Code: Select all

$filename = basename($path);

Code: Select all

$files = glob($dir . 'vuns/files/*');
    foreach ($files as $path) {
    	$filename = basename($path);
Try to use the filectime() function and tell us whether it works or not (just as a test not instead of filemtime()).
I still get the same error

Posted: Sun Apr 16, 2006 10:05 am
by Oren
Ok, what is the OS you are using to run this script?
What is the last modification date of the file? I mean the real one (check manually).

Posted: Sun Apr 16, 2006 10:06 am
by John Cartwright

Code: Select all

$files = glob($dir . 'vuns/files/*');
    foreach ($files as $path) {
       echo filemtime($dir.$path); 
    }
are you sure your pointing the file along with the dir like so?

Posted: Sun Apr 16, 2006 10:11 am
by feyd
the usage of basename() explains why. The file doesn't exist in the local directory, so filemtime() can't find the file.