Operating System - HP-UX
1833356 Members
3290 Online
110051 Solutions
New Discussion

Perl CGI using apache server.

 
Andy Nicastro
Occasional Advisor

Perl CGI using apache server.

Hi,
After creating an ASCII data file from within a browser application programmed in Perl CGI, I want the user to be able to save it. I am, therefore, trying to get the "File Download" popup to appear.
====
After creating the file in the apache server's /tmp/ diectory as defined in httpd,.conf, I use
=====
print "Content-Type: 'plain/text'; filename=\"$filename\"\n".
"Content-Disposition: inline; filename=\"$filename\"\n\n";
======
When I Open the file and read it, it writes to the browser instead of giving me the "File Download" popup.
=====
I can get it to work correctly if I first zip the file, but I'd like to give the user the option of not zipping it.
=====
Do you have any ideas?
Thanks very much,
Andy Nicastro
Publtec B.V.
a.nicastro@publitec.nl
10 REPLIES 10
Peter Godron
Honored Contributor

Re: Perl CGI using apache server.

Andy,
can the users not just use the right mouse button then save as?!
Or even right-click the link and save as.
Otherwise every document with the type 'plain/text' will bring up the pop-up.
Regards
Andy Nicastro
Occasional Advisor

Re: Perl CGI using apache server.

Hi,
Thanks for the very prompt reply.
Your solution is not an option because the format of the file changes when it comes into the browser (these are SQL*Loader files and their format must be preserved). In this application, it would not be a problem if every plain/text file caused the "File Download" popup to appear, but I cannot get the application to do this. Do you have any suggestions?
Thanks again.
Andy
Peter Godron
Honored Contributor

Re: Perl CGI using apache server.

Andy,
in the conf directory there should be a mime.type file.
Can you add the filename extension to the entry that contains the zip entry.
ON our machine:
before
text/plain asc txt
application/zip zip
after
text/plain asc
application/zip txt zip
So all files with a filename extension of txt should now use the popup.
NB. You have to stop and start the httpd.
Regards
Andy Nicastro
Occasional Advisor

Re: Perl CGI using apache server.

Hi,
Thanks again for the speedy reply.
This is what I tried:
1. In order to mimic your instructions exactly, I changed the extension name of the file from "dat" to "txt" in my code.
2. In the mime.types file I added one line AFTER â text/plain asc txtâ , namely
the line â application/zip txt zipâ
Please note that the line â application/zip zipâ already existed above â text/plain asc txtâ in mime.types.
3. Restarted the apache server.
4. Tried the application.
Still it writes the data to the browser rather than putting up the â File downloadâ popup.
The first line that appears in the browser is the result of the Perl print command, that is:
â Content-Type: "plain/text"; filename="CODE_LIBRARY_MAP.txt" Content-Disposition: inline; filename="CODE_LIBRARY_MAP.txt"
======
Any other ideas that I could try?
Your help is m
Peter Godron
Honored Contributor

Re: Perl CGI using apache server.

Andy,
you should have only one definition for txt in the file!
I have tried the reverse on our server, renaming a file to the .zip extension and it came up with the popup.
So not sure what the difference is.
Perhaps somebody else will come up with a clarification.

Sorry,
Pete
Andy Nicastro
Occasional Advisor

Re: Perl CGI using apache server.

Hi Pete,
You had it right! It works perfectly. I had a typo in my code. Adding the line: "application/zip dat zip" to the mime.types file does the trick. I wouldn't have found that in a million years.
One last queston then: Is there perhaps an alternative way that would not affect other applications? That is, can I add something to the httpd.conf file that would pertain only to applications that, for example, run from a particular directory or some such thing?
Thanks much for your help.
Greetings,
Andy
Peter Godron
Honored Contributor

Re: Perl CGI using apache server.

Andy,
that's good news, because I couldn't understand why it would not work on your system.
As far as I know, you can not change the behaviour of the mime.type on a directory basis. I mentioned that in my initial answer.
Sorry.
Hope this at least solved your initial question.
Regards
Andy Nicastro
Occasional Advisor

Re: Perl CGI using apache server.

Hi Pete,
Yes it has. And I thank you much.
Greetings,
Andy
Peter Godron
Honored Contributor

Re: Perl CGI using apache server.

Andy,
One POSSIBLE solution I thought of was to create a new extension and add it to the mime file. That would then not affect the rest of your system. It would not be based on the directory, but at least you can control the behaviour via the filename extension.

If you are happy with the solution, can you please identify which answered the question and close the thread.
Regards
Andy Nicastro
Occasional Advisor

Re: Perl CGI using apache server.

Peter Gordon has supplied a good solution and did so very quickly.
Thanks,
Andy