Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 28th, 2001, 04:26 AM
yhcmarc's Avatar
yhcmarc yhcmarc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Heemskerk, The Netherlands
Posts: 254 yhcmarc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 49 sec
Reputation Power: 8
show a random image

How do I select an image at random from a certain dir. ??

Marc

Reply With Quote
  #2  
Old July 28th, 2001, 11:39 AM
jdk's Avatar
jdk jdk is offline
phpkid ~~~~~~ :o)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Nov 2000
Location: NJ, USA
Posts: 2,535 jdk User rank is Lance Corporal (50 - 100 Reputation Level)jdk User rank is Lance Corporal (50 - 100 Reputation Level)jdk User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 11 m 11 sec
Reputation Power: 10
Send a message via Yahoo to jdk
Lightbulb ok..i got idea.

hi,

i m not giving u exact code.
but i can give u idea.

read all the images from directory in to array. i mean image names in array.
i hope how to do that.

after that find how many elements are tehre in array. that reflects no. of images in array.

now keep that as max. no. in generating random no.and use the generated random no. as a key to array get the filename and display it.

i hope u get the idea,

if u cant get idea, or cant write code,
post back,
jd
__________________
_____________________________
d.k.jariwala (JD)
~ simple thought, simple act ~
I blog @ http://jdk.phpkid.org

Reply With Quote
  #3  
Old July 28th, 2001, 02:30 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
Code:
$dir = '/home/path/to/randomimage';

# This is the web path to directory that holds the images
$weburl = 'http://www.yoursite.com/randomimage';

########################################################
# The script
########################################################
opendir(DIR, $dir) || die "$!";
 while ($_ = readdir DIR)
 {
   if(-f "$dir/$_"){
	 push(@dir, $_);
   }
 }
closedir(DIR);

$count = scalar @dir;
$i = int(rand( $count ));

print "Content-type: text/html\n\n";
print "<img src=\"$weburl/$dir[$i]\">";


This is just copied from a script i wrote a really long time ago that does exactly what you want.
__________________
Jon Coulter
ledjon@ledjon.com

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > show a random image


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway