Solved

how to set the filename for data that is sent to the browser  for downloading

Posted on 1998-09-29
2
161 Views
Last Modified: 2013-12-25
I use a perl cgi script to limit access to files to authorized users only. I send the files with content-type application/octet-stream so that they will be offered for saving to disk. Unfortunately the filename that the browser is proposing is derived from the cgi scriptname. How can I set that filename in the cgi script ?
0
Comment
Question by:um3814
2 Comments
 
LVL 11

Accepted Solution

by:
mouatts earned 100 total points
Comment Utility
The way to do this is to ensure that the name of the cgi sccript is the same as the file that you wish to download.

Remember that CGIs don't have to have a .cgi, .pl, or .exe extension just about any extension can be used but how you implement this depends on your web server and platform.

On most servers on Unix platforms the inclusion of the shell in the first line is enough unless you have limited the executable types within the server configuration.

On NT boxes you will need to build an executable which can not have an extension of any other non-executable type. The exception to this is the Oracle Web Server wher you should use the PL/SQL cartridge and the UTL_FILE package to output the files.

Alternatively if you have and API (eg ISAPI, NSAPI) for the server you can normally utilise this to handle things by (for example) treating all requests for certain extensions as requests for downloads of similarly named files within a given directory)

If your application allows one of a number of files to be downloaded then you will need to include a bit of javascript that will change the action attribute on the form when a file is selected. (You can also do this at the point the form is submitted)
(The API appoach mentioned above resolves this problem without using Javascript.)

This approach does mean that you will need a number of instances of your CGI each with an appropriate name (they don't need to be in the same directory as the data file so the name clash will not be a problem). Obviously if you are on a UNIX platform then you can use a symbolic link so that only one actual copy exists.

Having said all it may also be worthwhile including a NAME attribute within either the <A> or <FORM> as I have just had a vague recollection that some browsers may use this instead of the HREF or URL when present.

Steve
0
 

Author Comment

by:um3814
Comment Utility
I already supposed that it would be a tricky thing. I'm using Unix and I already know the method with symbolic links. As i cannot predict the name of the file, a solution is , to create the link and send a reload command for that link and then remove the link. But the link name must have the same name as the file
( incl. extension) and the extension will confuse the browser.
The content-type is not always the main criteria.
From all you said I learned , that the key point is to make the browser send an URL with the name of the file.





0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now