Current location: Hot Scripts Forums » General Community » Script Requests » Display 10 random images from DIR with HTML Code for Image


Display 10 random images from DIR with HTML Code for Image

Reply
  #1 (permalink)  
Old 05-14-06, 06:38 AM
cyclotron cyclotron is offline
Newbie Coder
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Display 10 random images from DIR with HTML Code for Image

I'm after a script where I have over 1800 funny images in a directory.

I need a script to randomly select a top 10 or 5 or whatever, (I should be able to change this value)

but under each spat out random image should be a text input box with the value of this

<a href="mysite.com"><img src="sitetorandomimage.jpg" /></a>

Thanks, hoping someone can help me out with this one!
Reply With Quote
  #2 (permalink)  
Old 05-14-06, 07:14 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I wrote this quick. Is that what you wanted?

PHP Code:

<?php


$path 
".";                                    // Path to images
$filter = array(".""..""rand.php");        // These files won't be displayed
$max_images 10;                            // Number of images to show
$site_url "http://mysite.com";            // Site url, image will link to this page

############################################################

$files = array();
$dir opendir($path);

while ((
$file readdir($dir)) !== false)
{
    if (!
in_array($file$filter))
    {
        
$files[] = $file;
    }
}

for (
$i 0$i $max_images$i++)
{
    
$rand rand(0count($files) -1);
    
    echo 
'<p><img src="'$path .'/'$files[$rand] .'" /></p>'"\n";
    echo 
'<p><input type="text" value="&lt;a href=&quot;'$site_url .'&quot;&gt;&lt;img src=&quot;'$path .'/'$files[$rand] .'&quot; /&gt;&lt;/a&gt;" /></p>' ."\n";
}

?>

Last edited by nico_swd; 05-14-06 at 08:03 AM.
Reply With Quote
  #3 (permalink)  
Old 05-14-06, 08:59 AM
cyclotron cyclotron is offline
Newbie Coder
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
That's perfect mate

Thankyou!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
html tutoral thefrtman HTML/XHTML/XML 5 04-27-09 10:25 AM
Display PHP in HTML page using JS scott2500uk PHP 6 05-18-06 12:25 PM
How do i make a CODE box in HTML? konabiker47 HTML/XHTML/XML 4 11-13-05 07:00 PM
Referencing HTML code from a second file msoucy HTML/XHTML/XML 2 07-18-05 12:25 AM
Can anyone help me ? (problem using php variables in html db insert code) chronic_ PHP 2 06-13-04 11:19 AM


All times are GMT -5. The time now is 11:22 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.