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!
[Back to original message]
|