473,799 Members | 2,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2058
"brett" <br*********@ho tmail.com> wrote in message
news:G6******** ************@ad elphia.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*****@agrico reunited.com>
comp.lang.javas cript 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*****@agrico reunited.com> wrote in message
news:rD******** *******@news2.m ts.net...
"brett" <br*********@ho tmail.com> wrote in message
news:G6******** ************@ad elphia.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*****@agrico reunited.com>
comp.lang.javas cript 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.infosystem s.www.authoring.cgi.
HTH
Jimbo
Jul 23 '05 #4
"J. J. Cale" <ph****@netvisi on.net.il> wrote in message
news:42******** @news.012.net.i l...
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.infosystem s.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
5469
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. I want to develop a webpage where people can send attachments that are stored on their local PC.
10
2470
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 to do this. The only problem is that it lists the asp file used to for example if i go to: "http://myserver/listing.asp" In the file listing will be "listing.asp" amongst a lot of marketing documents.
4
1538
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 listing file is just a copy of the source file with line numbers along with a list of syntax errors (e.g. multiply or undefined symbols).
3
3063
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 the event in a typical form with textboxes, drop down lists, etc. On this page there are also 4 file upload controls where the user can select 0 to 4 images on their file system for inclusion in the event listing. On submit, the images (if any)...
38
5079
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
2643
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 them in a browser doesn't take me to the file link. I have found examples for clickable URL's, FTP links and mailto addresses but not files. I am managing to produce output like this: <a...
13
1382
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 checkboxes within each cell are checked (wuth their dynamically assigned values). For example: cell 5 => condition 2 selected => box1, box3 checked cell 9 => condition 1 selected => box4 checked P.S: Below are relevant(?) snippets of my code. Thanks!
1
1959
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 listing and generating a web page of that listing, but I need to filter out files with the SYSTEM tag, so it wont show files I dont want it to, Below is my full code for the ASP page, I have Commented where I need to change the listing structure, if...
5
9119
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 db2 SELECT <blah command If I insert foo.txt in the db2cmd command line, the commands, result set, and messages go to foo.txt. That's sort of OK, except that running EXPORT, i can concoct the command with a file for output, and the...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10482
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10225
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.