Use opendir(), readdir(), and closedir() -

http://www.php.net/manual/en/function.opendir.php

HTH,

Jason Soza

----- Original Message -----
From: "Ashley M. Kirchner" <[EMAIL PROTECTED]>
Date: Monday, May 13, 2002 9:50 am
Subject: [PHP] Reading dir contents...

> 
>    Take this function:
> 
>      function randomImg() {
>        $numargs = func_num_args();
>        $ImgArray = array($numargs-1);
>        $arg_list = func_get_args();
>        $ImgDir = $arg_list[0];
>        srand((double)microtime()*1234567);
>        $img = $arg_list[rand(1,count($arg_list)-1)];
>        while(!$img) {
>          $img = $ImgArray[rand(1,count($ImgArray))];
>        }
>        return "$ImgDir/$img";
>      }
> 
> 
>    ...it assumes two things:  $arg_list[0] is a variable (which 
> is always
> passed) that ends up being $ImgDir, and then there's $arg_list[1-
> n] where 'n'
> is >1 .  Right now, I'm calling this function like so:
> 
>    <? echo randomImg("home", "bg01.gif", "bg02.gif", "bg03.gif"); ?>
> 
>    However, I'd like to change it so that I don't have to specify 
> the image
> names ($arg_list[1..n]), but just the first variable.  I'd like 
> for it to grab
> whatever it finds in that folder (passed as the variable), and 
> use.  This way I
> can have any number of images in that folder without having to 
> edit my pages
> every time to add or remove more.  And what if the image name 
> changes, once
> again I have to manually fix the function call in my pages.
> 
>    Can PHP do this; open that directory, read its contents and 
> use it (if so,
> how?)  Or do I have to go to Perl for this?
> 
> --
> W | I haven't lost my mind; it's backed up on tape somewhere.
>  +----------------------------------------------------------------
> ----
>  Ashley M. Kirchner <mailto:[EMAIL PROTECTED]>   .   303.442.6410 
> x130  IT Director / SysAdmin / WebSmith             .     
> 800.441.3873 x130
>  Photo Craft Laboratories, Inc.            .     3550 Arapahoe 
> Ave. #6
>  http://www.pcraft.com ..... .  .    .       Boulder, CO 80303, 
> U.S.A.
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to