Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> galeria 1 zdjecie
-Gość_fraksipon-
post
Post #1





Goście







czolem potrzebuje skrypt ktory bedzie losowo pokazywal jedno zdjecie na stronie z wybranego folderu pt: zdjecia
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Speedy
post
Post #2





Grupa: Zarejestrowani
Postów: 651
Pomógł: 28
Dołączył: 4.12.2004

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


Cytat(crash @ 2005-12-20 21:44:15)
  1. <?php
  2. $dir = './New/';
  3. $exts = array( 'gif', 'jpg', 'jpeg', 'png' );
  4. $imgs = array();
  5.  
  6. if( $d = opendir( $dir ) )
  7. {
  8.  while( $f = readdir( $d ) )
  9.  {
  10. $ext = explode( '.', $f );
  11. $ext = array_pop( $ext );
  12. if( in_array( strtolower( $ext ), $exts ) )
  13. {
  14.  $imgs[] = $f;
  15. }
  16.  }
  17.  closedir( $d );
  18. }
  19.  
  20. $img = $imgs[ array_rand( $imgs ) ];
  21.  
  22. echo '<img src="' . $dir . $img . '" alt="' . $img . '"/>';
  23. ?>

A 5zł wrzuć do mojej forumowej skarbonki... (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)

A co wtedy, gdy ktoś da sobie kropkę w nazwie pliku? (IMG:http://forum.php.pl/style_emoticons/default/snitch.gif) (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)

  1. <?php
  2. $dir = './New/';
  3. $exts = array( 'gif', 'jpg', 'jpeg', 'png' );
  4. $imgs = array();
  5.  
  6. if( $d = opendir( $dir ) )
  7. {
  8.  while( $f = readdir( $d ) )
  9.  {
  10. $path_parts = pathinfo($f);
  11. $ext = $path_parts['extension'];
  12. //$ext = explode( '.', $f );
  13. //$ext = array_pop( $ext );
  14.  
  15. if( in_array( strtolower( $ext ), $exts ) )
  16. {
  17.  $imgs[] = $f;
  18. }
  19.  }
  20.  closedir( $d );
  21. }
  22.  
  23. $img = $imgs[ array_rand( $imgs ) ];
  24.  
  25. echo '<img src="' . $dir . $img . '" alt="' . $img . '"/>';
  26. ?>
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: 25.12.2025 - 20:49