Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Najnowszy plik z danego folderu
Moby
post
Post #1





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 13.09.2003

Ostrzeżenie: (0%)
-----


Witam,
Jak zrobić skrypt, którywyświetli nazwę ostatnio modyfikowanego/najnowszego pliku z danego folderu?

Ten post edytował Moby 14.09.2006, 16:14:40
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Jim
post
Post #2





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 27.07.2005

Ostrzeżenie: (0%)
-----


  1. <?php
  2. function mostRecentModifiedFileTime($dirName,$doRecursive) {
  3.  $d = dir($dirName);
  4.  $lastModified = 0;
  5.  $lastName = '';
  6.  $currentModified = 0;
  7.  while($entry = $d->read()) {
  8.  if ($entry != "." && $entry != "..") {
  9.  if (!is_dir($dirName."/".$entry)) {
  10.  $currentModified = filemtime($dirName."/".$entry);
  11.  } else if ($doRecursive && is_dir($dirName."/".$entry)) {
  12.  $currentModified = mostRecentModifiedFileTime($dirName."/".$entry,true);
  13.  }
  14.  if ($currentModified > $lastModified){
  15.  $lastModified = $currentModified;
  16.  $lastName = $entry;
  17.  }
  18.  }
  19.  }
  20.  $d->close();
  21.  return array( 'filename'=>$lastName, 'modified'=>$lastModified );
  22. }
  23.  
  24.  
  25. $file=mostRecentModifiedFileTime(folder,true);
  26. echo $file['filename'];
  27.  
  28. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 20:01