?
Solved

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

Posted on 1998-09-29
2
Medium Priority
?
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
mouatts earned 200 total points
ID: 1828885
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
ID: 1828886
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to count occurrences of each item in an array.
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.
Suggested Courses

800 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