Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] Wyświetlanie plików według kolejności
Forum PHP.pl > Forum > Przedszkole
Lisek54
Witam,

W katalogu miniatury/ mam obrazki ponumerowane od 1 do 13, maja one rozszerzenie *.jpg
  1. <?php
  2. $dir = "miniatury/";
  3.  
  4. // Otwarcie prawidłowego katalogu i pobranie jego zawartości
  5. if (is_dir($dir)) {
  6.  if ($dh = opendir($dir)) {
  7.  while (($file = readdir($dh)) !== false) {
  8. $url = str_replace(".jpg", "", $file);
  9. if($file == '.') {}
  10. elseif($file == '..')
  11.  {
  12.  }
  13.  else
  14.  {
  15.  echo '<a href="foto.php?id='.$url.'" class="alfa2"><img src="miniatury/'.$file.'" alt="miniatura" /></a> ';
  16.  }
  17.  }
  18.  closedir($dh);
  19.  }
  20. }
  21. ?>


Tak je wyświetlam, problem pojawia się gdy jest ich więcej. Nie są one wyświetlane w kolejności od najmniejszej do największej. Są one porozrzucane Np. pierw jest 9 później 13, a na końcu jest 11.

Chciałbym aby zdjęcia z tego katalogu wyświetlały się od największego do najmniejszego.
Cytat
13.jpg 12.jpg 11.jpg 10.jpg ... .... 1.jpg


Szukałem pod hasłem sortowanie, ale znalazłem tylko rozwiązanie dla mysql.

Pozdrawiam
erix
Wrzucaj wszystko do tablicy, jako klucz ustaw nazwę plików i zrób tak jak tu:
http://forum.php.pl/index.php?showtopic=54908&hl=natsort
kamilmm
Witam...

mam taki skrypt galerii

  1. <?
  2. header("Cache-Control: no-store, no-cache, must-revalidate");
  3. header("Pragma: no-cache");
  4.  
  5. require('./sp_conf.php');
  6.  
  7. include $gheader;
  8. $header_html = str_replace('{NAME}', $gallery_name, $header_html);
  9. $header_html = str_replace('{DOWNLINK}', 'http://www.adresstrony.pl/', $header_html);
  10. $header_html = str_replace('{AUTHORLINK}', 'http://www.adresstrony.pl/', $header_html);
  11. $header_html = str_replace('{BACKLINK}', $back_link, $header_html);
  12. $header_html = str_replace('{CLOSELINK}', $close_link, $header_html);
  13. $header_html = str_replace('{COPYRIGHT}', $copyright, $header_html);
  14. $header_html = str_replace('{HOMELINK}', $home_link, $header_html);
  15. echo $header_html;
  16.  
  17. $dp = @opendir($directory);
  18. if ( !$dp )
  19. {
  20. echo "Opening directory " . $directory . " <b>failed</b>. Incorrect path?";
  21. echo "n<br />I cannot go on any longer. I'm sorry. I tried.n<br />";
  22. }
  23. else
  24. {
  25. $extensions = array(
  26. 'jpg',
  27. 'jpeg',
  28. 'gif',
  29. 'png',
  30. 'bmp',
  31. 'tiff',
  32. 'tif',
  33. 'psd'
  34. );
  35.  
  36. require($glayout);
  37.  
  38. $i=1;
  39. $x=1;
  40.  
  41. while ( $filename = readdir($dp) )
  42. {
  43. $theline = $line;
  44. $fileparts = explode(".", strrev($filename), 2);
  45. $name = strrev($fileparts[1]);
  46. $ext = strrev($fileparts[0]);
  47. unset($fileparts);
  48. if ( in_array(strtolower($ext), $extensions) )
  49. {
  50. if ( $x == 1 )
  51. {
  52. echo $line_start;
  53. }
  54. $image_url = './sp_images.php?size=' . $max_size . '&filename=' . $filename . '&action=thumb';
  55. $theline = str_replace('{IMAGE_URL}', $image_url, $theline);
  56. if ( $spoofing )
  57. {
  58. $link = './sp_images.php?filename=' . $filename . '&action=spoof';
  59. }
  60. else
  61. {
  62. $link = $images_uri . $filename;
  63. }
  64. $num = $x;
  65.  
  66. $theline = str_replace('{ROWPOS}', $num, $theline);
  67. $theline = str_replace('{NUMBER}', $i, $theline);
  68. $theline = str_replace('{LINK}', $link, $theline);
  69. $name = str_replace("%20", " ", $name);
  70. $name = str_replace("_", " ", $name);
  71. $theline = str_replace('{NAME}', $name, $theline);
  72. $theline = str_replace('{FILESIZE}', (int)(filesize($directory . $filename)/1024), $theline);
  73. $theline = str_replace('{FILENAME}', $filename, $theline);
  74. $theline = str_replace('{DOWNLINK}', 'http://www.adresstrony.pl/', $theline);
  75. $theline = str_replace('{AUTHORLINK}', 'http://www.adresstrony.pl/', $theline);
  76. echo $theline;
  77.  
  78. if ( $x == (int)$per_row )
  79. {
  80. echo $line_end;
  81. $x=1;
  82. }
  83. else
  84. {
  85. $x++;
  86. }
  87. $i++;
  88. }
  89. }
  90. $terminate_leftover = str_replace('{DOWNLINK}', 'http://www.adresstrony.pl/', $terminate_leftover);
  91. $terminate_leftover = str_replace('{AUTHORLINK}', 'http://www.adresstrony.pl/', $terminate_leftover);
  92. $terminate_leftover = str_replace('{NUMLEFT}', (($per_row-$x)+1), $terminate_leftover);
  93. echo $terminate_leftover;
  94. }
  95.  
  96. include $gfooter;
  97. $footer_html = str_replace('{NAME}', $gallery_name, $footer_html);
  98. $footer_html = str_replace('{DOWNLINK}', 'http://www.adresstrony.pl/', $footer_html);
  99. $footer_html = str_replace('{AUTHORLINK}', 'http://www.adresstrony.pl/', $footer_html);
  100. $footer_html = str_replace('{BACKLINK}', $back_link, $footer_html);
  101. $footer_html = str_replace('{CLOSELINK}', $close_link, $footer_html);
  102. $footer_html = str_replace('{COPYRIGHT}', $copyright, $footer_html);
  103. $footer_html = str_replace('{HOMELINK}', $home_link, $footer_html);
  104. echo $footer_html;
  105.  
  106. ?>


co zrobić aby zdjecia wyswietlały sie według nazw questionmark.gif?
moze mi ktos pomoc, mogę kogos prosić o poprawienie tego kodu?questionmark.gif

pozdrawiam
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.