RE: [PHP] Trying to list a directory content HELP PLEASE
| From: | Philip Olson | Date: | Fri, 07 Jun 2002 00:00:21 +0000 |
| Subject: | RE: [PHP] Trying to list a directory content HELP PLEASE | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-101044@lists.php.net to get a copy of this message | ||
This is not how readdir() works, it takes on
a directory resource from opendir()
http://www.php.net/readdir
I'm guessing you meant to put the directory
name into opendir() which will work, I don't
see any advantage to using chdir() here.
Maybe it's permissions or doesn't exist,
consider using a few other functions in there
such as is_dir() and file_exists().
Regards,
Philip Olson
On Thu, 6 Jun 2002, Scott Hurring wrote:
> Instead of chdir() try putting the path directly into
> readdir(); it'll make the code a tiny bit cleaner.
>
> readdir("/home/casapu/paginas/images/carteleras");
>
> ** and check return values! **
>
> $fd = readdir(...)
> if (!$fd) die("Cannot readdir");
>
> The code you have *should* work, but you'll never
> know why it's not working if you don't check return
> statuses
>
> ---
> Scott Hurring
> Systems Programmer
> EAC Corporation
> ScottH@eac.com
> Voice: 201-462-2149
> Fax: 201-288-1515
>
> > -----Original Message-----
> > From: Jason Wong [mailto:php-general@gremlins.com.hk]
> > Sent: Thursday, June 06, 2002 3:44 PM
> > To: php-general@lists.php.net
> > Subject: Re: [PHP] Trying to list a directory content HELP PLEASE
> >
> >
> > On Friday 07 June 2002 00:47, webmaster mbtradingco wrote:
> > > I know my doubt is probable odd, but I would ask your help please.
> > >
> > > I need a user to be able to select an image from a directory, from a
> > > drop down box. For this I need to list all the images
> > available on the
> > > directory, hence, I have this code:
> > >
> > > <select size="1" name="normal1">
> > > <?php
> > > chdir("/home/casapu/paginas/images/carteleras");
> > > $direc = opendir(".");
> > > while ($f = readdir($direc)); {
> > > print("<option
> > > value=\"".$f."\">".$f."</option>");
> > > }
> > > ?>
> > > .</select>");
> > >
> > > but this is not working. I have reviewed the code against all the
> > > manuals/books I have, and it says it should work but it
> > doesn't. Anyone
> > > knows what I'm doing wrong?
> >
> > how doesn't it work?
> >
> > --
> > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> > Open Source Software Systems Integrators
> > * Web Design & Hosting * Internet & Intranet Applications
> > Development *
> >
> > /*
> > Fashions have done more harm than revolutions.
> > -- Victor Hugo
> > */
> >
> >
> > --
> > 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
>