yoshida Posted September 29, 2006 Share Posted September 29, 2006 Hey it's me again. I stripped an image rotator like this: <?php$folder = 'c:\WINDOWS\Web\Wallpaper./';$extList['jpg'] = 'image/jpeg';$handle = opendir($folder);while ($file = readdir($handle)) { $file_info = pathinfo($file); $fileList[] = $file;}$imageNumber = time() % count($fileList);header ('Content-type: '.$extList[ $imageInfo['extension'] ]);readfile($folder.$fileList[$imageNumber]);closedir($handle);?> It displays a random image. I don't want that. I suspect it's because of $imageNumber's definition.How can I get this script to display all images in the folder? The folder name will be replaced by a variable which is propagated through a link. I'll make sure the folder exists and contains images.Thanks all. Link to comment Share on other sites More sharing options...
reportingsjr Posted September 29, 2006 Share Posted September 29, 2006 <?php$folder = 'c:\WINDOWS\Web\Wallpaper./';$extList['jpg'] = 'image/jpeg';$handle = opendir($folder);while ($file = readdir($handle)) { $file_info = pathinfo($file); $fileList[] = $file;}$imageNumber = time() % count($fileList);header ('Content-type: '.$extList[ $imageInfo['extension'] ]);readfile($folder.$fileList[$imageNumber]);closedir($handle);?> to <?php$folder = 'c:\WINDOWS\Web\Wallpaper./';$extList['jpg'] = 'image/jpeg';$handle = opendir($folder);while ($file = readdir($handle)) { $file_info = pathinfo($file); $fileList[] = $file;}for($i = "0", $i <= count($fileList), $i++){//echo out image, no clue how to do this lol.}closedir($handle);?> Try that out Link to comment Share on other sites More sharing options...
yoshida Posted September 29, 2006 Author Share Posted September 29, 2006 Tried something very similar, but all I got was a blank screen when I enclosed the three rules (imagenumber, header and readfile)The part where you don't have a clue is the relevant part... lol Link to comment Share on other sites More sharing options...
yoshida Posted September 30, 2006 Author Share Posted September 30, 2006 Cracked it! (Almost...) <?php$path=imgs;//Open images directory$dir = opendir("$path");//List files in images directorywhile (($file = readdir($dir)) !== false) { echo "<img src=$path\\$file>"; } closedir($dir);?> All I need to get rid off is 'false' images (<img src=imgs\.><img src=imgs\..>). Link to comment Share on other sites More sharing options...
justsomeguy Posted October 2, 2006 Share Posted October 2, 2006 Do some validating on the $file variable. You can use the is_dir function to check if it is a directory (. and .. are directories). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now