file listing within an html select box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brett

    #1

    file listing within an html select box

    On my website I have a directory filled with possible files that a user can
    select to download. Rather than going to the directory itself to download,
    I'd like the user to be able to select a single file from a select box
    embedded on an html page. I'm looking for a way that I can use javascript to
    do this for me. I know that perl could get these filenames for me easily,
    but is javascript able to put these into a select box once I have Perl parse
    the directory? Is this insecure or is there a better way to do this?

    Thanks for your help,
    Brett.


  • Grant Wagner

    #2
    Re: file listing within an html select box

    "brett" <brett_w2931@ho tmail.com> wrote in message
    news:G6mdnXWQot JqcoffRVn-ow@adelphia.com ...[color=blue]
    > On my website I have a directory filled with possible files that a
    > user can
    > select to download. Rather than going to the directory itself to
    > download,
    > I'd like the user to be able to select a single file from a select box
    > embedded on an html page. I'm looking for a way that I can use
    > javascript to
    > do this for me. I know that perl could get these filenames for me
    > easily,
    > but is javascript able to put these into a select box once I have Perl
    > parse
    > the directory? Is this insecure or is there a better way to do this?[/color]

    If you are using Perl to parse the directory, use it to populate the
    <select> as well. Parsing the list of files using Perl, then using Perl
    to output client-side JavaScript that can populate a <select> is an
    extra step and places a requirement on your end-user to have JavaScript
    enabled.

    print "content-type: text/html\n\n";
    if (opendir(DIR, "$full_path "))
    {
    @files = grep(/^[^\.]|[^\.\.]$/, readdir(DIR));
    closedir(DIR);

    @files = sort(@files);

    print "<select name=\"mySelect \">\n";
    for $filename (@files)
    {
    print "<option value=\"" . $filename . "\">" . $filename .
    "</option>\n";
    }
    print "</select>\n";
    }

    --
    Grant Wagner <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq


    Comment

    • brett

      #3
      Re: file listing within an html select box

      Grant,

      OK, that makes sense and I think the resulting code will be simpler.

      Lets just assume for a moment that I am a windows programmer who understands
      Perl, but have never added more than a form to a webpage. How would I
      include the output of this perl script in my webpage?

      Thanks,
      Brett.

      "Grant Wagner" <gwagner@agrico reunited.com> wrote in message
      news:rDMSd.214$ 3d3.749@news2.m ts.net...[color=blue]
      > "brett" <brett_w2931@ho tmail.com> wrote in message
      > news:G6mdnXWQot JqcoffRVn-ow@adelphia.com ...[color=green]
      > > On my website I have a directory filled with possible files that a
      > > user can
      > > select to download. Rather than going to the directory itself to
      > > download,
      > > I'd like the user to be able to select a single file from a select box
      > > embedded on an html page. I'm looking for a way that I can use
      > > javascript to
      > > do this for me. I know that perl could get these filenames for me
      > > easily,
      > > but is javascript able to put these into a select box once I have Perl
      > > parse
      > > the directory? Is this insecure or is there a better way to do this?[/color]
      >
      > If you are using Perl to parse the directory, use it to populate the
      > <select> as well. Parsing the list of files using Perl, then using Perl
      > to output client-side JavaScript that can populate a <select> is an
      > extra step and places a requirement on your end-user to have JavaScript
      > enabled.
      >
      > print "content-type: text/html\n\n";
      > if (opendir(DIR, "$full_path "))
      > {
      > @files = grep(/^[^\.]|[^\.\.]$/, readdir(DIR));
      > closedir(DIR);
      >
      > @files = sort(@files);
      >
      > print "<select name=\"mySelect \">\n";
      > for $filename (@files)
      > {
      > print "<option value=\"" . $filename . "\">" . $filename .
      > "</option>\n";
      > }
      > print "</select>\n";
      > }
      >
      > --
      > Grant Wagner <gwagner@agrico reunited.com>
      > comp.lang.javas cript FAQ - http://jibbering.com/faq
      >
      >[/color]


      Comment

      • J. J. Cale

        #4
        Re: file listing within an html select box

        > Lets just assume for a moment that I am a windows programmer who
        understands[color=blue]
        > Perl, but have never added more than a form to a webpage. How would I
        > include the output of this perl script in my webpage?[/color]

        As Grant explained you do it on the server. No javascript necessary. Grant's
        example is pure and simple cgi.
        One way is:
        Create an html page exactly the way you want the client to see it using a
        <select> to display the file names.

        Copy everything in the html source up to (but not including) the <select> to
        a file. I use something.hdr. Copy the rest of the code after the </select>
        and save it as something.ftr.

        Now using Grant's code; the first line is the HTTP content type header. MUST
        have two linefeeds at the end unless you're outputting other headers(Cookie
        or something). Then just one :>}
        <snip>[color=blue][color=green]
        > > print "content-type: text/html\n\n";[/color][/color]

        read the something.hdr file and output it on the fly to stdout
        [color=blue][color=green]
        > > if (opendir(DIR, "$full_path "))
        > > {
        > > @files = grep(/^[^\.]|[^\.\.]$/, readdir(DIR));
        > > closedir(DIR);
        > >
        > > @files = sort(@files);
        > >
        > > print "<select name=\"mySelect \">\n";
        > > for $filename (@files)
        > > {
        > > print "<option value=\"" . $filename . "\">" . $filename .
        > > "</option>\n";
        > > }
        > > print "</select>\n";
        > > }[/color][/color]

        read something.ftr to stdout and your done.

        This will output your page as a whole to the clients machine.
        You can probably get some help from comp.infosystem s.www.authoring.cgi.
        HTH
        Jimbo


        Comment

        • brett

          #5
          Re: file listing within an html select box

          "J. J. Cale" <photom@netvisi on.net.il> wrote in message
          news:421c218e$1 @news.012.net.i l...[color=blue][color=green]
          > > Lets just assume for a moment that I am a windows programmer who[/color]
          > understands[color=green]
          > > Perl, but have never added more than a form to a webpage. How would I
          > > include the output of this perl script in my webpage?[/color]
          >
          > As Grant explained you do it on the server. No javascript necessary.[/color]
          Grant's[color=blue]
          > example is pure and simple cgi.
          > One way is:
          > Create an html page exactly the way you want the client to see it using a
          > <select> to display the file names.
          >
          > Copy everything in the html source up to (but not including) the <select>[/color]
          to[color=blue]
          > a file. I use something.hdr. Copy the rest of the code after the </select>
          > and save it as something.ftr.
          >
          > Now using Grant's code; the first line is the HTTP content type header.[/color]
          MUST[color=blue]
          > have two linefeeds at the end unless you're outputting other[/color]
          headers(Cookie[color=blue]
          > or something). Then just one :>}
          > <snip>[color=green][color=darkred]
          > > > print "content-type: text/html\n\n";[/color][/color]
          >
          > read the something.hdr file and output it on the fly to stdout
          >[color=green][color=darkred]
          > > > if (opendir(DIR, "$full_path "))
          > > > {
          > > > @files = grep(/^[^\.]|[^\.\.]$/, readdir(DIR));
          > > > closedir(DIR);
          > > >
          > > > @files = sort(@files);
          > > >
          > > > print "<select name=\"mySelect \">\n";
          > > > for $filename (@files)
          > > > {
          > > > print "<option value=\"" . $filename . "\">" . $filename .
          > > > "</option>\n";
          > > > }
          > > > print "</select>\n";
          > > > }[/color][/color]
          >
          > read something.ftr to stdout and your done.
          >
          > This will output your page as a whole to the clients machine.
          > You can probably get some help from comp.infosystem s.www.authoring.cgi.
          > HTH
          > Jimbo[/color]

          It does, but after some research i've realised our webserver allows SSIs, so
          i've just added an execute command in there to get it to work.

          Brett.


          Comment

          Working...