Jump to content


Photo

Warning: filemtime() stat failed for ...


  • This topic is locked This topic is locked
10 replies to this topic

#1 MasterACE14

MasterACE14

    Advanced Member

  • Members
  • PipPipPip
  • 2,680 posts
  • LocationSydney, Australia

Posted 28 November 2008 - 09:08 PM

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

Don't bother just to be better than your contemporaries or predecessors. Try to be better than yourself. ~William Faulkner


#2 vicodin

vicodin

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationLong Island

Posted 28 November 2008 - 09:50 PM

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.
Web Designer: 4Yrs.
PHP:2 Yrs.
MySQL:2Ysr.

#3 ShiloVir

ShiloVir

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts
  • LocationError 404. Location Not Found! (Winnipeg)

Posted 28 November 2008 - 10:23 PM

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

#4 kenrbnsn

kenrbnsn

    Advanced Member

  • Staff Alumni
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 29 November 2008 - 12:32 AM

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

#5 corbin

corbin

    Advanced Member

  • Staff Alumni
  • 8,129 posts

Posted 29 November 2008 - 01:39 AM

$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)))
Why doesn't anyone ever say hi, hey, or whad up world?

#6 MasterACE14

MasterACE14

    Advanced Member

  • Members
  • PipPipPip
  • 2,680 posts
  • LocationSydney, Australia

Posted 30 November 2008 - 04:55 AM

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  ???

Don't bother just to be better than your contemporaries or predecessors. Try to be better than yourself. ~William Faulkner


#7 kenrbnsn

kenrbnsn

    Advanced Member

  • Staff Alumni
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 30 November 2008 - 09:56 AM

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

#8 wsams

wsams

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 15 October 2012 - 03:50 PM

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");
}


#9 wsams

wsams

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 15 October 2012 - 04:13 PM

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);

Edited by wsams, 15 October 2012 - 04:14 PM.


#10 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 15 October 2012 - 04:27 PM

"Late reply"..? It's 4 years!
Keeping it simple.

#11 Pikachu2000

Pikachu2000

    I hate everything.

  • Staff Alumni
  • 11,378 posts
  • LocationFuture Independent Republic of Texas
  • Age:106

Posted 15 October 2012 - 04:48 PM

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.
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *

Random Quote: "




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com