Jump to content

Archived

This topic is now archived and is closed to further replies.

MasterACE14

Warning: filemtime() stat failed for ...

Recommended Posts

I have a function for displaying files and folders within a directory. I have added the filemtime() function to display the time the file was last modified but I'm receiving this warning and I am having no luck with finding out how to fix it on google:

 

Warning: filemtime() [function.filemtime]: stat failed for mail.php in /home/eliteace/public_html/updatez/includes/functions.inc.php on line 41

note: this is just 1 warning, the function returns about 40 files all with the same warning.

 

 

here's my script:

<?php
function display_folder($dirname) {

   $dir = opendir($dirname);
   
   $file_list = '';
   
   while(false !== ($file = readdir($dir))) {
      if(($file != ".") and ($file != "..")) {
         if(is_dir($dirname . '/' . $file)) {
            $file_list .= "<li style=\"color: red\">{$file}\n<ul>";
            $file_list .= display_folder($dirname . '/' . $file);
            $file_list .= "</ul>\n</li>\n";
         }
         elseif(substr($file,"-4") == ".php") {
            $file_list .= "<li style=\"color: aqua;\">$file</li>" . date("H, d M",strtotime(filemtime($file))) . "\n";
         }
         else {
            $file_list .= "<li style=\"color: yellow;\">$file</li>" . date("H, d M",strtotime(filemtime($file))) . "\n";
         }
      }
   }
   closedir($dir);
   return $file_list;
}

 

any help is greatly appreciated.

 

Regards ACE

Share this post


Link to post
Share on other sites

i could be wrong but it looks like you are trying to run that function on a directory instead of a file. Thats what i am seeing but i could be wrong.

Share this post


Link to post
Share on other sites

Files for internet are "/" while files on a server are "\" If your trying to get all on the server try "\"

Share this post


Link to post
Share on other sites

Files for internet are "/" while files on a server are "\" If your trying to get all on the server try "\"

No, backslashes, "\", are used on Windows machines for file paths. PHP will accept a forward slash "/" and do the right thing on a Windows machine. There is no need to use backslashes when programming PHP.

 

Ken

Share this post


Link to post
Share on other sites

$file is the actual file.

$dirname is the directory.  They are relative to the script being run, so they need to be combined to work.

 

 

For example some/folder/then/file.txt.  $file would be file.txt and $dirname would be some/folder/then.

 

 

So, you need date("H, d M",strtotime(filemtime($dirname . '/' . $file)))

Share this post


Link to post
Share on other sites

you need date("H, d M",strtotime(filemtime($dirname . '/' . $file)))

 

That has got rid of the Warnings. But it is showing every date as...

18, 31 Dec

 

Which isn't right, the files have been modified at different times, and in the past few months. Not the future in December 31  ???

Share this post


Link to post
Share on other sites

The filemtime function returns a UNIX timestamp, so you don't have to use the strtotime function.

 

<?php
echo date("H, d M",filemtime($dirname . '/' . $file));
?>

 

Ken

Share this post


Link to post
Share on other sites

I know this is a late reply, but often there's a pesky newline character in your variable sent to filemtime() or other functions.

 

I see this a lot when globbing. The code below removes those line endings. Both \r and \n.

 

$files = glob("*.jpg");
foreach ($files as $file) {
   $file = preg_replace("/(\r|\n)/", "", $file);
   $mtime = date("Y-m-d H:i:s", filemtime($file));
   print($mtime . "\n");
}

Share this post


Link to post
Share on other sites

Just want to note that the same thing happens for file() calls, but you can supply a second argument like the following to prevent that,

 

<?php
$files = file("my.log", FILE_IGNORE_NEW_LINES);

Share this post


Link to post
Share on other sites

Notwithstanding the fact that this thread is OLD, trim will also remove linefeeds/newlines, along with spaces and others, without the expense of a regex pattern.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.