473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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.
Jul 23 '05 #1
4 2041
"brett" <br*********@hotmail.com> wrote in message
news:G6********************@adelphia.com...
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?


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 <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
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" <gw*****@agricoreunited.com> wrote in message
news:rD***************@news2.mts.net...
"brett" <br*********@hotmail.com> wrote in message
news:G6********************@adelphia.com...
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?


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 <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3
> 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?


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>
print "content-type: text/html\n\n";
read the something.hdr file and output it on the fly to stdout
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";
}


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.infosystems.www.authoring.cgi.
HTH
Jimbo
Jul 23 '05 #4
"J. J. Cale" <ph****@netvision.net.il> wrote in message
news:42********@news.012.net.il...
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?


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>
print "content-type: text/html\n\n";
read the something.hdr file and output it on the fly to stdout
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";
}


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.infosystems.www.authoring.cgi.
HTH
Jimbo


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.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
10
by: Chris | last post by:
Hi, Not sure if this is the right forum, but hopefully someone can help me. I am creating something for our intranet and i want to list the files and folders of a directory, i found some code...
4
by: Grant Austin | last post by:
Hello, This might be a tad off topic. The c-programming groups I found appear to be unused... The problem is simple... I need to create a listing file from an assembler source file. The...
3
by: Pitcairnia | last post by:
The basic purpose of the site is for authenticated users to post event listings, which often include photographs. The user is faced with a page where they can insert all of the information about...
38
by: ted | last post by:
I have an old link that was widely distributed. I would now like to put a link on that old page that will go to a new page without displaying anything.
7
by: Jeff Gaines | last post by:
I have spent the day learning how to use Zend Development Environment. I can now produce a list of files in a directory, filtered by extension, and apparently clickable. Unfortunately clicking on...
13
by: phub11 | last post by:
Hi all, I have a table to which an array of cloned checkboxes can be dropped in (using scriptabulous). Could someone please tell me how I can get a list of all populated cells, and which...
1
by: =?Utf-8?B?RVFOaXNo?= | last post by:
Not sure if this is the spot to ask but I need some help with a script I hijacked and put to my own use in an .ASP page any ways I am using the FilesystemObjects to get a directory and file...
5
by: MeBuggyYouJane | last post by:
This should be simple, and the docs say so, but no... 1) I have an .hta file (VBScript), with a call to windoze shell 2) the shell call is to db2cmd, input from a file 3) the command file has a ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.