RE: [PHP] I can't read directory contents
| From: | Peter Benoit | Date: | Thu, 29 Jun 2000 20:36:07 +0000 |
| Subject: | RE: [PHP] I can't read directory contents | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-3885@lists.php.net to get a copy of this message | ||
*smacks head*
Thanks Ben, got it working! You've been a great help!
-----Original Message-----
From: Ben Gollmer [mailto:ben@jatosoft.com]
Sent: Wednesday, June 28, 2000 4:35 PM
To: Peter Benoit
Cc: php-general@lists.php.net
Subject: RE: [PHP] I can't read directory contents
Oh, I see - you have to set $currentDir to whatever directory you want to
read. Opening a null directory will always fail :)
Put this at the top of your script (except of course put the directory you
want to read).
$currentDir = "/home/username/www";
Ben Gollmer
Jatosoft, LLC
http://www.jatosoft.com/
At 04:13 PM 6/29/2000 -0400, you wrote:
>No, it's the error specified in your script:
>
>Error: Cannot open directory $currentDir.
>
>except $currentDir never shows up so all I see is:
>
>"Error: Cannot open directory"
>
>
>-Peter
>
>-----Original Message-----
>From: Ben Gollmer [mailto:ben@jatosoft.com]
>Sent: Wednesday, June 28, 2000 4:19 PM
>To: Peter Benoit
>Cc: php-general@lists.php.net
>Subject: RE: [PHP] I can't read directory contents
>
>
>What's the exact error? Something about "Access Denied"? Perhaps the user
>PHP is running as doesn't have read access to your directories.
>
>I'm not sure why a directory listing would be a security issue, especially
>for publicly accessible HTML files. That's something you'd have to ask your
>ISP...
>
>Ben Gollmer
>Jatosoft, LLC
>http://www.jatosoft.com/
>
>
>At 03:51 PM 6/29/2000 -0400, you wrote:
> >Ya, sometimes you see so much it just all looks confusing...
> >
> >Your script returns the Error message every time, which I guess means I
> >can't read the contents of the directory?
> >
> >Is there a permission that needs to be set for this? What if my host
says
> >it's a security issue?
> >
> >Thanks again,
> >Peter
> >
> >-----Original Message-----
> >From: Ben Gollmer [mailto:ben@jatosoft.com]
> >Sent: Wednesday, June 28, 2000 3:54 PM
> >To: Peter Benoit
> >Cc: php-general@lists.php.net
> >Subject: Re: [PHP] I can't read directory contents
> >
> >
> >I think the problem lies in the exec( "ls -la $dir",$lines,$rc) line. ls
> >doesn't do anything under NT.
> >
> >Try using the built-in filesystem functions in PHP. For example:
> >
> >$theDir = @opendir($currentDir);
> >if (!$theDir)
> >{
> > print ("<b>Error: Cannot open directory
> > $currentDir.</b><br>");
> >}
> >else
> >{
> > while($filename = readdir($theDir))
> > {
> > print $filename;
> > print ("<br>");
> > }
> >}
> >
> >This will print out all the files in the directory $currentDir. Works
under
> >both NT and Linux. Just add an ereg or two in there to match html files,
> >and you should be set.
> >
> >Ben Gollmer
> >Jatosoft, LLC
> >http://www.jatosoft.com/
> >
> >
> >At 03:23 PM 6/29/2000 -0400, you wrote:
> > >Hi,
> > >
> > >I was using the following code on my Unix server which worked just
fine.
> > >Now on my NT server, the host company states that I cannot read the
> > >directory contents and write them to this page because it's a security
> > >problem.
> > >
> > >Simply put, this should look for .htm files in a directory, and print
>them
> > >out on the page. It doesn't work now, but it works fine on my Unix
host
> > >machine.
> > >
> > >Is this a security problem? Is there a setting I need on NT? Can't I
do
> > >this with the standard read permissions?
> > >
> > >What do I need in order for a script like this to work?
> > >
> > >TIA,
> > >Peter
> > >
> > >
> > ><?php
> > > exec( "ls -la $dir",$lines,$rc);
> > > $count = count($lines) - 1;
> > > for ($i = 1; $i <= $count; $i++) {
> > > $type = substr($lines[$i],0,1);
> > > $name = strrchr($lines[$i], " ");
> > > $name = substr($name,1);
> > > $dire = substr($lines[$i],0,strpos($lines[$i],$name));
> > > if (strpos($name, ".mp3")) {
> > > //echo "<font color=\"red\">";
> > > } else {
> > > if (strpos($name, ".php") or strpos($name, ".cgi")) {
> > > // echo "<font color=\"maroon\">";
> > > } else {
> > > if ($type == "d") {
> > > //echo "<font color=\"blue\">";
> > > } else {
> > > //echo "<font color=\"black\">";
> > > }
> > > }
> > > }
> > > //echo "$dire</font>";
> > > if ($type == "d") {
> > > if ($name == "." or $name == "..") {
> > > echo "";
> > > } else {
> > > if ($dir == "") {
> > > // echo "<a
>href=directory.php?dir=$name>$name</a><br>";
> > > } else {
> > > // echo "<a
> > >href=directory.php?dir=$dir/$name>$name</a><br>";
> > > }
> > > }
> > > } else {
> > > if ($dir == "" and !strpos($name, ".php") and
> > > !strpos($name,
> > >".text")) {
> > > echo " <P><font face=\"verdana,arial\">[<a
> >href=$name>view</A>]
> > >: <a href=source.php3?page_url=$name>$name</a><br>";
> > > } else {
> > > // echo " <P><font
> > > face=\"verdana,arial\">[<a
> > >href=$name>view</A>] : <a
> > >href=source.php3?page_url=$dir/$name>$name</a><br>";
> > > }
> > > }
> > > }
> > > ?>
> > >
> > >--
> > >PHP General Mailing List (http://www.php.net/)
> > >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > >For additional commands, e-mail: php-general-help@lists.php.net
> > >To contact the list administrators, e-mail:
php-list-admin@lists.php.net
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> >For additional commands, e-mail: php-general-help@lists.php.net
> >To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net