Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Sortowanie plików wg daty
david8213
post 30.10.2017, 10:49:51
Post #1





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


  1. <?PHP
  2. $OpenDir=opendir(".");
  3. while (($file = readdir($OpenDir))!=false)
  4. { if(($file!=".") && ($file!="..") && ($file!="index.php") && ($file!="images") && ($file!="style.css") && ($file!="czytaj.php") && ($file!="data.txt") && ($file!="licznik.txt") && ($file!="return.php")&& ($file!="add.php")&& (is_file($file)))
  5. {
  6. echo("<a href='$file' target=blank><img src='$file' width=150></a> ");
  7. }
  8. }
  9. ?>


Co i gdzie dopisać żeby wyświetlało pliki wg daty od ostatniego pliku wrzuconego na serwer żeby był na początku

Ten post edytował david8213 30.10.2017, 10:51:01
Go to the top of the page
+Quote Post
2 Stron V   1 2 >  
Start new topic
Odpowiedzi (1 - 19)
viking
post 30.10.2017, 11:03:52
Post #2





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


https://stackoverflow.com/questions/2667065...-by-date-in-php


--------------------
Go to the top of the page
+Quote Post
david8213
post 31.10.2017, 14:10:07
Post #3





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


Wyświetlanie plików... nie działa wg daty

  1. <?PHP
  2.  
  3. $files = array();
  4. if ($handle = opendir('.')) {
  5. while (false !== ($file = readdir($handle))) {
  6. if ($file != "." && $file != "..") {
  7. $files[filemtime($file)] = $file;
  8. }
  9. }
  10. closedir($handle);
  11.  
  12.  
  13. ksort($files);
  14.  
  15. $reallyLastModified = end($files);
  16.  
  17. foreach($files as $file) {
  18. $lastModified = date('F d Y, H:i:s',filemtime($file));
  19. if(strlen($file)-strpos($file,".jpg")== 4){
  20. if ($file == $reallyLastModified) {
  21.  
  22. }
  23. echo "<a href=\"$file\" target=\"_blank\">$file</a>$lastModified";
  24. }
  25. }
  26. }
  27.  
  28.  
  29.  
  30. ?>
Go to the top of the page
+Quote Post
viking
post 31.10.2017, 14:16:12
Post #4





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Działa. Przykładowy wynik samych dat (krsort zamiast ksort):
Kod
October 31 2017, 13:15:13
October 10 2017, 07:35:48
October 09 2017, 05:34:49
September 25 2017, 15:28:58


--------------------
Go to the top of the page
+Quote Post
david8213
post 31.10.2017, 14:20:30
Post #5





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


Tak teraz działa. Dziękuję
Co nalezy zmienić zeby wyswietlało mi oprócz plików JPG pliki BMP, JPEG, i PNG ?
Go to the top of the page
+Quote Post
viking
post 31.10.2017, 14:56:55
Post #6





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


  1. $dir = new FilesystemIterator(__DIR__, FilesystemIterator::SKIP_DOTS);
  2. $ext = ['jpg', 'png', 'bmp'];
  3. $files = [];
  4.  
  5. foreach ($dir as $fileinfo) {
  6. if (!in_array($fileinfo->getExtension(), $ext)) continue;
  7. $files[$fileinfo->getMTime()][] = $fileinfo->getFilename();
  8. }
  9. krsort($files);
  10. var_dump($files);


--------------------
Go to the top of the page
+Quote Post
david8213
post 31.10.2017, 15:26:11
Post #7





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


niestety nie znam się na tyle żeby to zastosować do mojego kodu
Go to the top of the page
+Quote Post
viking
post 31.10.2017, 15:30:15
Post #8





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Pętli nie umiesz zastosować? Zero myślenia i tylko czekanie na gotowe. Skopiuj sobie z kodu wyżej.


--------------------
Go to the top of the page
+Quote Post
david8213
post 31.10.2017, 15:33:59
Post #9





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


Gdybym się na tym znał to bym nie prosił o pomoc
Go to the top of the page
+Quote Post
viking
post 31.10.2017, 15:38:29
Post #10





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


To sobie poczytaj jak iterowac po elementach tablicy. I dobrze napisałeś. Pomoc a nie cały kod który ktoś za ciebie będzie pisał. Dane juz masz.


--------------------
Go to the top of the page
+Quote Post
david8213
post 31.10.2017, 15:58:04
Post #11





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


ten cały kod co podałeś ma być wykorzystany ? czy to jest jakiś przykład
Go to the top of the page
+Quote Post
viking
post 31.10.2017, 16:06:33
Post #12





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Uruchom go to się dowiesz.


--------------------
Go to the top of the page
+Quote Post
david8213
post 31.10.2017, 16:16:19
Post #13





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


  1. <?PHP
  2.  
  3. $dir = ".";
  4. $dirnew = new FilesystemIterator(__DIR__, FilesystemIterator::SKIP_DOTS);
  5. $ext = ['jpg', 'png', 'bmp'];
  6. $files = [];
  7. if ($handle = opendir($dir)) {
  8. while (false !== ($file = readdir($handle))) {
  9. if ($file != "." && $file != ".." && $file != "index.php") {
  10. $files[filemtime($file)] = $file;
  11. }
  12. }
  13. closedir($handle);
  14.  
  15. krsort($files);
  16. var_dump($files);
  17.  
  18.  
  19. $reallyLastModified = end($files);
  20.  
  21. foreach ($dirnew as $fileinfo) {
  22. $lastModified = date('F d Y, H:i:s',filemtime($file));
  23. if (!in_array($fileinfo->getExtension(), $ext)) continue;
  24. $files[$fileinfo->getMTime()][] = $fileinfo->getFilename(); {
  25. if ($file == $reallyLastModified) {
  26.  
  27. }
  28. echo "<a href=\"$file\" target=\"_blank\"><img src=\"$file\" width=\"130\"></a>&nbsp;";
  29. }
  30. }
  31. }
  32.  
  33. ?>
  34.  
  35.  
Go to the top of the page
+Quote Post
viking
post 31.10.2017, 16:18:46
Post #14





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Mój kod na pewno tak nie wyglądał. O tym śmietniku wcześniej zapomnij.


--------------------
Go to the top of the page
+Quote Post
david8213
post 31.10.2017, 16:23:26
Post #15





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


Jak uruchamiam twój kod to nic się nie dzieje

  1. <?
  2. $dir = new FilesystemIterator(__DIR__, FilesystemIterator::SKIP_DOTS);
  3. $ext = ['jpg', 'png', 'bmp'];
  4. $files = [];
  5.  
  6. foreach ($dir as $fileinfo) {
  7. if (!in_array($fileinfo->getExtension(), $ext)) continue;
  8. $files[$fileinfo->getMTime()][] = $fileinfo->getFilename();
  9. }
  10. krsort($files);
  11. var_dump($files);
  12. ?>
Go to the top of the page
+Quote Post
viking
post 31.10.2017, 16:24:06
Post #16





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Bo pewnie masz wyłączoną składnię <?. Używaj <?php


--------------------
Go to the top of the page
+Quote Post
david8213
post 31.10.2017, 16:26:04
Post #17





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


Używam <?PHP


Ten post edytował david8213 31.10.2017, 16:30:00
Go to the top of the page
+Quote Post
viking
post 31.10.2017, 16:28:15
Post #18





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


No jakoś nie widzę w kodzie wyżej. W najgorszym razie wyświetli Array(0){}. Więc sprecyzuj co to znaczy "nic się nie dzieje"


--------------------
Go to the top of the page
+Quote Post
david8213
post 31.10.2017, 16:30:54
Post #19





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


Znalazłem inne rozwiązanie. Wyświetle wszystkie pliki i ukryje te których nie chcę aby były widoczne. Trudno inaczej nie potrafię


  1. <?PHP
  2.  
  3. $files = array();
  4. if ($handle = opendir('.')) {
  5. while (false !== ($file = readdir($handle))) {
  6. if ($file != "." && $file != ".." && $file != "...........ukryte pliki.......................") {
  7. $files[filemtime($file)] = $file;
  8. }
  9. }
  10. closedir($handle);
  11.  
  12.  
  13. ksort($files);
  14.  
  15. $reallyLastModified = end($files);
  16.  
  17. foreach($files as $file) {
  18. $lastModified = date('F d Y, H:i:s',filemtime($file));
  19. if(strlen($file)-strpos($file,".")== 4){ // kropka wyświetli wszystkie pliki a nie tylko .JPG
  20. if ($file == $reallyLastModified) {
  21.  
  22. }
  23. echo "<a href=\"$file\" target=\"_blank\">$file</a>$lastModified";
  24. }
  25. }
  26. }
  27.  
  28.  
  29.  
  30. ?>


Może znajdzie się ktoś kto mi pomoże





Ten post edytował david8213 31.10.2017, 18:23:33
Go to the top of the page
+Quote Post
viking
post 31.10.2017, 16:51:23
Post #20





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


http://tpcg.io/7dFp1I

Działa. U ciebie nie działa. Bardzo ciekawe.


--------------------
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 13:41