Re: Create array from directory
| From: | Chris Blake | Date: | Mon, 14 Apr 2003 07:56:27 +0000 |
| Subject: | Re: Create array from directory | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143726@lists.php.net to get a copy of this message | ||
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 ?
Thanks
Chris
On Fri, 2003-04-11 at 14:10, Lowell Allen wrote:
> > From: Chris Blake <cblake@pbpc.co.za>
> >
> > Greetings learned PHP(eople),
> >
> > I wish to create an array of images from a specific directory.
> > On PHP.net I searched using "arrays from directories" and got taken thru
> > to here :
> >
> > http://marc.theaimsgroup.com/?l=php-general&r=1&w=2&q=b&s=%22arrays+from+direc
> > tories%22
> >
> > Which didn`t help !
> >
> > I also went to the news server on PHP but it tells me "news cannot be
> > found". (?)
> >
> > Where can I access the archives to search through ?
> > I know this info was sent to me in my welcome email, but that has gone
> > AWOL.
>
> Searching for "arrays from directories" here returns a bunch of results:
> <http://marc.theaimsgroup.com/?l=php-general>
>
> And here's how I do it:
>
> $current_dir = $DOCUMENT_ROOT . "/" . $dir_name . "/";
> $dir = @opendir($current_dir);
> $gallery = array();
> while ($file = readdir($dir)) {
> $filepath = $current_dir . $file;
> if ($file != '.' && $file != '..' && is_dir($filepath))
> {
> array_push($gallery, $file);
> }
> }
> closedir($dir);
> sort($gallery);
> reset($gallery);
>
> --
> Lowell Allen
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
Chris Blake
Office : (011) 782-0840
Cell : 083 985 0379
Linux vs. Windows is a no WIN situation.