Nahodný obrazek
5 příspěvků
Archiv diskusního fóra
Fórum je uzavřené a slouží pouze ke čtení. Některé informace mohou být zastaralé.
-
Mám PHP zobrazující náhodný obrázek: <? $images = array("images/image1.gif", "images/image2.gif", "images/image3.gif", "images/image4.gif"); mt_srand(time()); $random_index = mt_rand(1, (count($images))); $random_index--; ?> <IMG src="<? echo "$images[$random_index]" ?>" > Jak zařídím aby vybíral obrázky z určeného adresáře a nemusel jsem je tam vypisovat?
-
no nactes obsah toho adresare do toho pole. nejlip pomoci funkci opendir, readdir, closedir. a do toho pole bych to nedaval s cestou, pokud to neni vylozene nutny (jako ze neni, kdyz jsou vsecky v jednom adresari) a tohle je co? $random_index = mt_rand(1, (count($images))); $random_index--; co treba $random_index = mt_rand(0, count($images)-1);
-
co se týká PHP jsem uplný laik, z toho důvodu jsem si kod stahnul odsud: http://www.jaknaweb.com/script-ukazka/233/nahodny-obrazek
-
tohle ti nacte obrazky do pole: if($dir = opendir('cesta_k_adresari_s_obrazkama')) { while(($file = readdir($dir)) !== false) { if(($file != '.') && ($file != '..')) { $images[] = $file; } } closedir($dir); } a takhle nejak to pak vypises do html (to vlastne zustane stejny, akorat se tam musi doplnit ta cesta): <img src="<?php echo('cesta_k_adresari_s_obrazkama'.$images[rand(0, count($images)-1)]); ?>">
-
na http://cz2.php.net/ nalezneš spoustu inspirace ke zkoušení Zatím zkus tohle: <?php $images = array(); $handle=opendir('images'); while (false!==($file = readdir($handle))) { if ($file != "." && $file != "..") { $images[] = $file; } } closedir($handle); $random_index = mt_rand(0, count($images)-1); $img='images/'.$images[$random_index]; list($width, $height, $type, $attr) = getimagesize("$img"); echo "<img src=\"$img\" $attr alt=\"getimagesize() example\" />"; ?>