You are here: Need to capture only 5 random urls from a directory of hundreds « PHP Programming Language « IT news, forums, messages
Need to capture only 5 random urls from a directory of hundreds

Posted by guttyguppy on 12/16/05 03:58

This code:

<?
//PHP SCRIPT: getimages.php
Header("content-type: application/x-javascript");

//This function gets the file names of all images in the current
directory
//and ouputs them as a JavaScript array
function returnimages($dirname="images") {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"; //valid image
extensions
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'fadeimages['.$curimage.']=["images/'.$file .'", "", ""]';
echo "\n";
$curimage++;
}
}

closedir($handle);
}
return($files);
}

echo 'var fadeimages=new Array();'; //Define array in JavaScript
echo "\n";

returnimages() //Output the array elements containing the image file
names
?>

captures every file in the images directory into the fadeimages array.
How can I tell php to randomly capture only 5 or so of the images and
store only those in the array? Any help would be greatly appreciated!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация