SEO Forums















                                          
User   Password   remember     (register)  ?

Display a random picture


Back to php.


thibault    (2009-12-16)

thibault

Display a random picture

Every webmaster encountered this problem at least one time when coding his pages : How to display a random picture from one folder or even several folders?

Here is a simple way to do it in PHP. I just made this script, so do not hesitate if you have ideas for any improvement. In brief, the script fills an array with every file it founds in the specified folders, then it creates a random number and selects a picture.

Please see the responses to find the script.


thibault    (2009-12-16 13:11:26)

thibault

Display a random picture

<?

$pic_directories = array();

$pic_directories[0] = 'images_0';  // Just add other lines for several folders

$pic_image = array();
$pic_directory = array();

foreach($pic_directories as $pic_dir)
if (is_dir($pic_dir))
if ($dh = opendir($pic_dir))
{
while (($pic_file = readdir($dh)) !== false)
if ($pic_file != '...' && $pic_file != '..' && $pic_file != '.')
{
$pic_image[] = $pic_file;
$pic_directory[] = $pic_dir;
}

closedir($dh);
}

$pic_total = count($pic_image)-1;
$pic_random = rand(0, $pic_total);

print '<img src="'.$pic_directory[$pic_random].'/'.$pic_image[$pic_random].'" title="'.substr($pic_image[$pic_random],0,strpos($pic_image[$pic_random],'.')).'">';

?>



ficgs
Suggestions

  Display Random Image or Quote
javascript.about.com/library/blrand.htm

 PHP Random Images | Randomizing Scripts & Programs | Hot Scripts
www.hotscripts.com/category/php/scripts-programs/randomizing/random-images/

 How to Display a Random Image
www.mediacollege.com/internet/javascript/image/random.html



ficgs
More suggestions

This is a collaborative page, you may change the order of these suggestions by registering, then clicking the icons before the titles.


  WP Widgets » blog.oddy.net
blog.oddy.net/wordpress-widgets

 A List Apart: Articles: Random Image Rotation
www.alistapart.com/articles/randomizer/

 displaying random images on web page using javascript - random image display on web page
www.webdevelopersnotes.com/tutorials/javascript/random_image_display_javasc

 AnvSoft Flash Slide Show Maker - display random picture from folder with flash
flash.dvd-photo-slideshow.com/myspace-slideshow-free/display_random_picture

 Cool Display Pictures, Avatars, Icons - avatarsvault
www.avatarsvault.com/

 Random Image Displayer
www.bezveze.com/skripte/rid/

 Xaraya :: display random picture
www.xaraya.com/index.php/xarbb/topic/2658

 Revived Wire Media, formerly Big Lick Media - Scripts - php Random Image Displayer - web design, web development, hosting and corporate identity - Roa...
www.biglickmedia.com/misc/php/random-image.php

  Random Image Display on Page - Dynamic Drive Forums
www.dynamicdrive.com/forums/showthread.php?p=65373

 Random Image Display script 0.5 Free Scripts Download - Random Image Display is a simple PHP script to display a random
www.rocketdownload.com/scripts/program/random-image-display-script-8901.htm

 Display a random image, with JavaScript
www.mjrweb.co.uk/latest/view/display-a-random-image-with-javascript/9

 Free random image display download - random image display script - Top 4 Download
scripts.top4download.com/free-random-image-display/

 PHP random image rotation script for your website
www.marcofolio.net/webdesign/php_random_image_rotation.html



Response  
  Smilies

Guest name   (optional)       Register for more options.


عرضت صورة عشوائيّة    (ar)
Дисплей на случаен принцип карти    (bg)
Zobrazuje náhodně obraz    (cs)
Udviser en tilfældig billede    (da)
Zeigen Sie eine gelegentliche Abbildung an    (de)
Επιδείξτε μια τυχαία εικόνα    (el)
Exhiba un cuadro al azar    (es)
نمايش‌ يك تصوير تصادفي‌    (fa)
Näyttö pistokokein kuva    (fi)
Montrez une image aléatoire    (fr)
Nuna da mahaɗin kafaɗa hoto    (ha)
תצוגה א אקראי התמונה    (he)
तस्वीर का यादृच्छिक प्    (hi)
Megjelenítés egy véletlenszerűen kiválasztott kép    (hu)
Visualizzi un'immagine casuale    (it)
任意映像を表示しなさい    (ja)
무작위 그림을 표시하십시오    (ko)
Toon een willekeurig beeld    (nl)
Skjerm en tilfeldig billede    (no)
Wyświetlacz losowo wybranej obrazu    (pl)
Indique um retrato aleatório    (pt)
Afisajul o intamplare tablou    (ro)
Покажите случайно изображение    (ru)
Ekran JEDAN slujan sliku    (sr)
Visa ett slumpmässigt föreställer    (sv)
จะแสดง ภาพ แบบสุ่ม    (th)
Bir Açığa gelişigüzel resim    (tr)
ایک بےقصد تصویر اویزاں    (ur)
显示一张任意图片    (zh)




Trackbacks : If you talked about this article in your blog or website, you may instantly get a backlink 
  There's no trackback at the moment.









 

FICGS message




SEO forums and chat - Search engines optimization



 

March 19, 2010

 

Buttons: Facebook, Twitter, MySpace, Google, Technorati, Yahoo buzz... Ficgs Facebook Myspace Twitter Google Technorati Stumble upon Delicious Digg Yahoo buzz Wikio Furl Reddit Linkedin Squidoo Newsvine Yahoo My Web Blogmarks Comments Blinklist Email

Write upside down !
(works with Twitter, Facebook, MySpace, Youtube, MSN, Yahoo, Bebo, Hi5...)







FICGS is also a Free Internet Correspondence Games Server.

Here you can play Chess, Go & Poker Texas Holdem online for free in rated class tournaments and a unique world championship.

Free Internet Chess & Go Server


Feel free to link to FICGS :