Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] automatyczna galeria zdjęć
Przemo75
post
Post #1





Grupa: Zarejestrowani
Postów: 66
Pomógł: 2
Dołączył: 9.03.2004
Skąd: POLSKA

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


Witam,
Mam problem z automatyczną galerią zdjęć, a mianowicie zdjęcia NIE są wyświetlane wg nazwy tylko chaotycznie. Natomiast ta sama galeria lokalnie wyświetla się poprawnie.

Kod galerii:
  1. <?php
  2.  
  3. /* settings */
  4. $image_dir = 'galeria2/';
  5. $thumb_dir = 'galeria2/miniaturki/';
  6. $per_column = 4;
  7.  
  8. /* step one: read directory, make array of files */
  9. if ($handle = opendir($thumb_dir)) {
  10. while (false !== ($file = readdir($handle)))
  11. {
  12. if ($file != '.' && $file != '..')
  13. {
  14. $files[] = $file;
  15. }
  16. }
  17. closedir($handle);
  18. }
  19.  
  20. /* step two: loop through, format gallery */
  21. if(count($files))
  22. {
  23. foreach($files as $file)
  24. {
  25. @$count++;
  26. echo '<a class="photo-link" rel="lightbox[set1]" href="',$image_dir,$file,'"><img src="',$thumb_dir,$file,'" width="120" height="90" /></a>';
  27. if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
  28. }
  29. }
  30. else
  31. {
  32. echo '<p>Brak zdjęć w galerii.</p>';
  33. }
  34.  
  35. ?>

Nazwy plików wyglądają tak: ogrod2_01.jpg, ogrod2_02.jpg, itd.
Go to the top of the page
+Quote Post
krzywy36
post
Post #2





Grupa: Zarejestrowani
Postów: 370
Pomógł: 43
Dołączył: 1.12.2007
Skąd: Kędzierzyn Koźle

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


stringi łączy się kropkami a nie przecinkami, tu:
  1. echo '<a class="photo-link" rel="lightbox[set1]" href="',$image_dir,$file,'"><img src="',$thumb_dir,$file,'" width="120" height="90" /></a>';


--------------------
pretty as a shit.
Go to the top of the page
+Quote Post
Przemo75
post
Post #3





Grupa: Zarejestrowani
Postów: 66
Pomógł: 2
Dołączył: 9.03.2004
Skąd: POLSKA

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


Problem rozwiązany. Poniżej właściwy kod:
  1. <?php
  2.  
  3. /* settings */
  4. $image_dir = 'galeria2/';
  5. $thumb_dir = 'galeria2/miniaturki/';
  6. $per_column = 4;
  7.  
  8. /* step one: read directory, make array of files */
  9. settype($files, 'array');
  10. if ($handle = opendir($thumb_dir)) {
  11. while (false !== ($file = readdir($handle)))
  12. {
  13. if ($file != '.' && $file != '..')
  14. {
  15. array_push($files, $file);
  16. }
  17. }
  18. closedir($handle);
  19. }
  20.  
  21. natsort($files);
  22.  
  23. /* step two: loop through, format gallery */
  24. if(count($files))
  25. {
  26. foreach($files as $file)
  27. {
  28. @$count++;
  29. echo '<a class="photo-link" rel="lightbox[set1]" href="',$image_dir,$file,'"><img src="',$thumb_dir,$file,'" width="120" height="90" /></a>';
  30. if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
  31. }
  32. }
  33. else
  34. {
  35. echo '<p>Brak zdjec w galerii.</p>';
  36. }
  37. ?>


Ten post edytował Przemo75 22.03.2011, 10:06:03
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: 21.08.2025 - 05:00