我有一個小型的python cgi腳本,它接受來自用戶的圖像上傳,轉換成不同的格式,並將新文件保存在臨時位置。我希望它自動提示用戶下載轉換後的文件。我曾嘗試:生成後的CGI下載圖像
# image conversion stuff....
print "Content-Type: image/eps\n" #have also tried application/postscript, and application/eps
print "Content-Disposition: attachment; filename=%s\n" % new_filename #have tried with and without this...
print open(converted_file_fullpath).read()
print
我也曾嘗試:
print "Location: /path/to/tmp/location/%s" % new_filename
print
我的瀏覽器或者下載script.cgi
或script.cgi.ps
。任何幫助表示讚賞。
當你的瀏覽器下載到錯誤的文件名,哪些數據是在文件中?這是你期望的數據嗎? – 2010-07-09 19:04:21
是的,當它下載script.cgi時,文件看起來像一個postscript文件。當它作爲script.cgi.ps下載時,我得到正確的圖像,但下載時使用「錯誤」文件名困擾我... – 2010-07-09 19:07:51