Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Losowy obrazek
dolmi2
post
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 13.01.2004

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


Mam taki oto skrypt powodujący wyświetlanie losowego obrazka z danego katalogu.

  1. <?php 
  2. $path = '.'; 
  3. $i = 0; 
  4. $imgDir = opendir ($path); 
  5.    while ( $file = readdir( $imgDir ) ) 
  6.    {     
  7.       $file_type = strrchr( $file, &#092;".\" ); 
  8.       $is_image = eregi( &#092;"jpg|gif\",$file_type ); 
  9.       if ( $file != '.' && $file != '..' && $is_image ) 
  10.       { $images[$i++] = $file; } 
  11.    } 
  12. closedir ($imgDir); 
  13. srand( (double) microtime()*1000000 ); 
  14. $image_name = $path . '/' . $images[rand( 0,sizeof( $images ) -)]; 
  15. $imgSize = GetImageSize( $image_name ); 
  16. if ( $i == 0 ) 
  17.    die(); 
  18. print ( &#092;"<img src=\"\" . $image_name . \"\"\" . $imgSize[3] . \" />n\" ); 
  19. ?>


Mój problem polega na tym, że nie wiem, jak zrobić, aby skrypt ten wyświetlał tylko pliki mniejsze niż na przykład 5kB. Czy jest jakiś sposób, aby to wymóc na skrypcie? Za radą znajomego zmieniłem 9. linijkę na
Kod
if ( $file != '.' && $file != '..' && $is_image && filesize($file)<5121)

ale niestety to nic nie dało. Proszę o pomoc.

Ten post edytował dolmi2 20.12.2004, 21:34:47
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
hwao
post
Post #2


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




  1. <?php
  2. $banery = file(&#092;"banery.txt\");
  3. $ile= &#092;"3\";
  4.  
  5. srand ((float)microtime()*1000000); 
  6. shuffle($banery); 
  7. for($i=0;$i<$ile;$i++){
  8.  list($adres,$img,$opis) = explode('|+|', $banery[$i]);
  9.  
  10.  echo &#092;"<a href=\"$adres\" target=\"_blank\" title=\"$opis\"><img src=\"baner/$img\" border=\"0\"></a><br />\";
  11. }
  12. ?>


Troche stare ale dziala :]
Tablica zamien na ta co robi Dir" title="Zobacz w manualu PHP" target="_manual() i wywal explod'y ;-)
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: 3.10.2025 - 13:50