Forum Moderators: coopster
fadeimages[0]="photo1.jpg"
fadeimages[1]="photo2.jpg"
fadeimages[2]="photo3.jpg"
...
and so on
I have been trying to make a php script that reads a folder and searches for images. with those images, it uses a loop to print each image in such way so that the javascript will be able to work!
here is my php script! (i have had no luck!)
$dir = "images/random/";
// Open a known directory, and proceed to read its contents
if ($dh = opendir($dir)) { // open the dir
while (($file = readdir($dh))!= false) // read the files
{
$ext = explode('.',$file);
if ($file!= '.' && $file!= '..' && $ext[1]=='jpg' && $ext[1]=='gif' && $ext[1]=='jpeg' && $ext[2]!='LCK') {
$filearray = explode('.',$file);
$filename = reset($filearray);
/* $getcat = urlencode($filename);
for ($n = "0"; $n >= 0; $n++) { */
print ('fadeimages[$n]="/$dir$filename"\n');
/* } */
}
}
closedir($dh);
}
thanks for any help!
<?
$the_array = Array();
$handle = opendir('/root/path/to/dir');
while (false!== ($file = readdir($handle))) {
if ($file!= "." && $file!= ".." &&!is_dir($file)) {
$namearr = split('\.',$file);
if ($namearr[count($namearr)-1] == 'jpg') $the_array[] = $file;
}
}
closedir($handle);
sort ($the_array);
reset ($the_array);
// output
$counter = 0;
while (list ($key, $val) = each ($the_array)) {
echo 'fadeimages[' . $counter . ']="' . $val . '"' . "\n";
$counter++;
}
?>
only reason was ahmedtheking mentioned needing it to be written to js, not sure why I cat'ed so many times, could be written like so
echo 'fadeimages[',$counter,']="',$val,'"',"\n";
which is much faster as the string doesn't have to be concatenated before it can be displayed.