Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [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
mike
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

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


Wybierasz pliki z folderu a potem za pomocą filectime() lecisz po nich i wybierasz najnowszy.
Go to the top of the page
+Quote Post
Moby
post
Post #3





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

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


Znalazłem coś takiego do wyświetlania daty ostatnio zmodyfikowanego pliku, ale jak wyświetlić jego nazwę?

  1. <?php
  2.  
  3. function mostRecentModifiedFileTime($dirName,$doRecursive) {
  4.  $d = dir($dirName);
  5.  $lastModified = 0;
  6.  while($entry = $d->read()) {
  7.  if ($entry != "." && $entry != "..") {
  8.  if (!is_dir($dirName."/".$entry)) {
  9.  $currentModified = filemtime($dirName."/".$entry);
  10.  } else if ($doRecursive && is_dir($dirName."/".$entry)) {
  11.  $currentModified = mostRecentModifiedFileTime($dirName."/".$entry,true);
  12.  }
  13.  if ($currentModified > $lastModified){
  14.  $lastModified = $currentModified;
  15.  }
  16.  }
  17.  }
  18.  $d->close();
  19. return $lastModified;
  20.  
  21. } 
  22.  
  23.  
  24. $data=mostRecentModifiedFileTime(folder,false);
  25. echo date("Y/m/d", $data); 
  26.  
  27.  
  28. ?>


Znalazłem takie coś:

http://www.phpclasses.org/browse/package/3367.html

Niektóre możliwości:
- wygenerowanie listy plików i folderów
- sortowanie listy plików
- wyszukanie najnowszego pliku
- sprawdzanie objętości plików/folderów/podfolderów i kombinacji
- i różne inne...
Go to the top of the page
+Quote Post
Jim
post
Post #4





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

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

 



RSS Aktualny czas: 20.08.2025 - 08:10