Random Pic Of The Day Script.

windows

Guest
Hey guys.<br /><br />I am looking for a script of some kind that would display a random pic from the bunch of pics on my page for me.<br /><br />Trick is, i need it to pick ANY picture (No spcial naming convention) from given folder AND have ability to go into foders within, looking for more pictures. Follow me? Not sure i am clear.<br /><br />Basicly i need it to display all and any picture (Say all .JPG) from this folder even if there are other folders with pictures inside main folder.<br /><br />I found some scripts but none of them seems to be able to do what i need it to.<br /><br />Anyone?<br /><br />Eugene<!--content-->
This is what I used to use. I'm not even sure where I originally picked up the example, but I'm not the original author of it, but I do know it's free to use.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /><br /><br /># Put the SERVER PATH to image directory.<br /># INCLUDE trailing slash<br />$dir = "/home/youraccount/public_html/images/random/";<br /><br /><br /># Put the HTML PATH to image directory.<br /># DO NOT include trailing slash<br />$html_dir = "http://www.******/images/random";<br /><br /><br />$dir_handle = opendir($dir);<br />$image_array = array();<br /><br /><br /># This opens up the image directory, grabs all files with a ".jpg" extension<br /># and puts them into an array. You can set whatever extension you'd like here.<br /># Just switch out the .jpg for .gif, etc. If you have more than one extension,<br /># replace this line with something like this:<br /># if (($file !=".") && ($file !="..") && (substr($file, -4) == ".jpg") || (substr($file, -4) == ".gif"))) {<br /># This will pull up all .jpg OR .gifs. If you name all the images you want to pull<br /># a certain way (example, image-thumb.jpg or image.thumb.jpg) you can do this:<br /># if (($file !=".") && ($file !="..") && (substr($file, -10) == ".thumb.jpg")) {<br /># basically you want to put the extension in quotes and then count how many characters<br /># it is and place that after $file, -<br /><br /><br />while ($file = readdir($dir_handle)) {<br />if (($file !=".") && ($file !="..")) {<br />$file_name = "$html_dir/$file";<br />$image_array[$file_name] = $file_name;<br />}<br />}<br /><br /><br /># sorts the array. For some reason this won't work at all<br /># unless this is done. Can anyone tell me why?<br />sort($image_array);<br /><br /><br />$count = sizeof($image_array);<br /><br /><br /># trims all the URLs of whitespace and assigns each<br /># item in the array a number to identify it.<br />for($i = 0;$i<$count; $i++) {<br />$image[$i] = rtrim($image_array[$i]);<br />}<br /><br /><br /># assign a random value<br />$r = rand(0,$count-1);<br /><br /><br /># get the size of a random image<br />$size = getimagesize($image[$r]);<br />$width = $size[0];<br />$height = $size[1];<br /><br /><br /># This is the HTML output. You can change any of this, but you should<br /># leave src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/\"$image[$r]\" width=\"$width\" height=\"$height\" where it is.<br /># Remember to escape any quotation marks, etc.<br />$img_src = <!-- m --><a class="postlink" href="http://www.totalchoicehosting.com/forums/lofiversion/index.php/"&">http://www.totalchoicehosting.com/forum ... php/"&</a><!-- m -->#60;center><img src=\"$image[$r]\" width=\"$width\" height=\"$height\" vspace=\"5\" border=\"1\" alt=\"This is a Random Image\" /></center>";<br /><br />echo $img_src;<br /><br /># closes the directory (why keep it open?)<br />closedir ($dir_handle);<br /><br /><br />?><!--c2--></div><!--ec2--><!--content-->
Yes, good script, thanx.<br /><br />But it do not look like it would go into additional folders inside of main folder. Or will it?<br /><br />Eugene<!--content-->
Moving for organization.<!--content-->
 
Back
Top