Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Returning a CSV file from CGI

by willdooUK (Beadle)
on Sep 17, 2001 at 21:43 UTC ( [id://112911]=perlquestion: print w/replies, xml ) Need Help??

willdooUK has asked for the wisdom of the Perl Monks concerning the following question:

Hi - I have a csv file sitting in a directory that only my CGI script can see. This is good, 'cos it means that it can't be got at from a web browser.

I want to let the sales team get at the file, so I'm writing an HTML page which submits a password to a simple CGI script. The script should check the password is OK, then return the CSV file.


However:

What I'd like to happen is for the browser to pop up a 'save as' dialogue box, and let the user save the file. This is what would happen if I gave the users the direct URL of the file.

At the moment, I can only manage to get the script to print it out to the browser, so the content appears as a web page.

Can I get the CGI to not splurge it out to the page? Change the header type maybe? I guess it has something to do with the perceived MIME type.

Any help is much appreciated.

willdooUK
--------------
"Home is a castle you built in my mind; I'm home anywhere, anytime."
Donny Hathaway

Replies are listed 'Best First'.
Re: Returning a CSV file from CGI
by earthboundmisfit (Chaplain) on Sep 17, 2001 at 21:51 UTC
    Yes, you can alter the MIME type of the displayed page by calling $q->header('application/unknown');
Re: Returning a CSV file from CGI
by arturo (Vicar) on Sep 17, 2001 at 22:04 UTC

    You could also use your webserver's built-in access control to do this job. Simply put the file in a directory and tell your webserver that only those with the right password can access the files in that directory.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://112911]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-26 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found