By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,556 Members | 990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,556 IT Pros & Developers. It's quick & easy.

"save as" python script

P: 1
I have a script "licence.cgi" write in python which generate text files and I would like that the user click on a button and he can download this file.

_1er solution:_
I found in my research that I have to add the Content-Disposition... So I created an other script call /download.cgi /and I obtain a popup "save as" but how the script "licence.cgi" can give the variable filename to the script download.cgi?

-----------------------------------------------------------*_
licence.cgi
_*print "Content-type: text/html"
print
...
filename="/var/www/licence/licence-20070511-152214"
...
print '<form name="input" action=%s method="POST"><INPUT TYPE="SUBMIT" VALUE="VIEW the file"></form>' %filename
print '<form method="POST" action="/cgi-bin/downloadfile.cgi"> <INPUT TYPE="SUBMIT" VALUE="DOWNLOAD the file"></form>'
...

-----------------------------------------------------------
download.cgi
#!/usr/bin/python

import string, sys
import cgi
import cgitb; cgitb.enable()

print "Content-Disposition: attachment; filename= %s " %filename
print "Content-Type: application/text"
print

try:
fp=open(licencefile, "r")
content = fp.read()
print content
except:
print "Couldn't find the file."
-----------------------------------------------------------
_
2 solution:_
I would like to have only one script, only "licence.cgi". How can I do ?


Thanks you very much for your help
--

Laetitia
May 14 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.