Solved

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

Posted on 1998-09-29
2
166 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 100 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
ROBOFTP UNZIP 1 66
Powershell script to compare two directory content difference only ? 5 71
Ruby or Python 7 122
script to read text file 34 19
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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