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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
ozzy
Forum Commoner
Posts: 74
Joined: Tue Apr 11, 2006 4:45 pm

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

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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();
}
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

What is the last modification time of the file?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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?
User avatar
ozzy
Forum Commoner
Posts: 74
Joined: Tue Apr 11, 2006 4:45 pm

Post 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. :(
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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?
User avatar
ozzy
Forum Commoner
Posts: 74
Joined: Tue Apr 11, 2006 4:45 pm

Post 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. :)
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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).
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's $filename in this particular case?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Try to use the filectime() function and tell us whether it works or not (just as a test not instead of filemtime()).
User avatar
ozzy
Forum Commoner
Posts: 74
Joined: Tue Apr 11, 2006 4:45 pm

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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).
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the usage of basename() explains why. The file doesn't exist in the local directory, so filemtime() can't find the file.
Post Reply