Re: Create array from directory
| From: | David Robley | Date: | Tue, 15 Apr 2003 01:40:04 +0000 |
| Subject: | Re: Create array from directory | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143856@lists.php.net to get a copy of this message | ||
In article <1050306987.2215.35.camel@pb004.pbpc.co.za>, cblake@pbpc.co.za
says...
> Howdy Mr. Allen,
>
> First off, thanks for the assistance...I found a similar example at
> php.net after looking up is_file(), however, my problem is still there.
>
> Running the code below just turns up an empty page :
> -----------------------------------------------------------
> <?php
>
> $image_dir = '../graphics/';
> $dir = opendir($image_dir);
> $gallery = array();
>
> while ($file = readdir($dir))
> {
> $filepath = $image_dir . $file ;
> if (($file !='.' && $file !='..') &&
> is_file($filepath))
> {
> array_push($gallery, [$file]);
> }
> }
> closedir($dir);
> sort($gallery);
> srand ((float)microtime()*1000000);
> shuffle ($gallery);
> ?>
> <html>
> <head>
> <title>Shuffling Arrays</title>
> </head>
> <body>
> <center>
> <H1>Shuffling Arrays</H1>
> <table width="100%">
> <tr>
> <?php
> for ($i = 0; $i < 3; $i++)
> {
> print '<td align = "center"><img src = "';
> print ($filepath);
> print '" width = "100" height =
> "100"></img></td>';
> }
>
> print $filepath;
> ?>
> </tr>
> </table>
> </center>
> </body>
> </html>
> -----------------------------------------------------------------
> The intention behind this is to open a dir, place all the images into
> the array and then randomly select 3 images for display on the page.
>
> I`ve tried a few things now but still a blank page !
>
> Any ideas ?
That code appears to create an array $gallery of filenames - however you
don't appear to use that array when you are trying to display; the
following code may work as you expect
<H1>Shuffling Arrays</H1>
<table width="100%">
<tr>
<?php
for ($I = 0; $I < 3; $I++)
{
echo '<td align = "center"><img src = "';
echo $gallery{$I};
echo '" width = "100" height =
"100"></img></td>';
}
// print $filepath;
?>
</tr>
</table>
--
Quod subigo farinam
$email =~ s/oz$/au/o;