how can i list a directory into a browser?? 
Author Message
 how can i list a directory into a browser??

I want to list a directory into a Netscape/Explorer browser, and each
file i list will have a hyperlink.

How can i do??

Please, answer me quickly

Thanks



Wed, 18 Jun 1902 08:00:00 GMT  
 how can i list a directory into a browser??



Quote:
> I want to list a directory into a Netscape/Explorer browser, and each
> file i list will have a hyperlink.

> How can i do??

> Please, answer me quickly

> Thanks

This is snipped from a larger prog, but you should be able to modify it
to do what you want.

opendir(DOCDIR,$path) || die "$!";

foreach (readdir(DOCDIR)) {
        print "<A href=\"$_\">$_</A> <BR>";

Quote:
}

closedir(DOCDIR) || die "$!";

HTH,

Jeremy Gurney
SAS Programmer  |  Proteus Molecular Design Ltd.
"Sometimes I think the so-called experts actually are experts."

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Wed, 18 Jun 1902 08:00:00 GMT  
 how can i list a directory into a browser??


Quote:
> This is snipped from a larger prog, but you should be able to modify
it
> to do what you want.

> opendir(DOCDIR,$path) || die "$!";

> foreach (readdir(DOCDIR)) {
>    print "<A href=\"$_\">$_</A> <BR>";
> }

> closedir(DOCDIR) || die "$!";

Which won't actually work, doh! (At least not in a CGI environment)

The original had a variable $urlpath which was used in the link, I'm
sure you could do something similar.

Of course there's always the good old fashioned way of getting the web
server to do all this for you by linking to a dir with no index file (or
default etc. etc.).

Jeremy Gurney
SAS Programmer  |  Proteus Molecular Design Ltd.
"Sometimes I think the so-called experts actually are experts."

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Wed, 18 Jun 1902 08:00:00 GMT  
 how can i list a directory into a browser??
Hi,

Quote:

> I want to list a directory into a Netscape/Explorer browser, and each
> file i list will have a hyperlink.

> How can i do??

using Perl ?
unlink 'index.html';

Quote:

> Please, answer me quickly

Quick enough ?

Christoph



Wed, 18 Jun 1902 08:00:00 GMT  
 how can i list a directory into a browser??

Quote:
> I want to list a directory into a Netscape/Explorer browser, and each
> file i list will have a hyperlink.

Something like :

#!/usr/bin/perl -w

use CGI qw(:standard);

my $filename = param('filename');

my $directory = param('directory') || '/home/gellyfish';

my $me = script_name();

if ($filename)
  {
    $fullpath = "$directory/$filename";

    if ($filename =~ /html*$/ )
      {
        $content = 'text/html';
      }
    elsif ( -T $fullpath )
      {
        $content = 'text/plain';
      }
    else
     {
        $content = 'application/x-unknown';
     }

    if ( open(INFILE,$fullpath) )
      {
        print header(-type => $content);
        while(<INFILE>)
          {
            print $_;
          }
        close INFILE;
       }
     else
       {
         print header,start_html('Oops');

         print h1('Couldnt open the file');

         print end_html;
       }
  }
else
  {
    print header,start_html("Directory of : $directory");

    if ( opendir(DIR,$directory ))
      {

        closedir(DIR);
        print "<UL>\n";

          {
            print "<LI>\n";
            print "<A HREF='$me?filename=$_'>$_</A>\n";
            print "</LI>\n";
          }
        print "</UL>\n";
        print end_html;
      }
    else
      {
        print h1("Cant open the directory");
        print end_html;
      }
   }

Of course using this could create a security hole big enough to drive a
space shuttle through - but there you go ...

/J\
--

<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Help with directory listing: filenames or directories

2. Directory listing query with Net::FTP::list

3. Directory listing query with Net::FTP::list

4. looking for directory utility to use in browser

5. Curses Directory Browser ala pine/pico

6. parsing canned response

7. question about canned perl script

8. Troubles with a Canned script

9. canned reply script

10. canned reply??

11. canned replies

12. values obtained from a browser in a multiple option list

 

 
Powered by phpBB® Forum Software