[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 1998-09-29
2
Medium Priority
?
169 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
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 …
Suggested Courses

656 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