簡體   English   中英

無法使用python cgi腳本引發“文件下載”對話框

[英]unable to Raise a “File Download” Dialog Box using python cgi script

在我的追求下,在客戶端窗口中彈出一個下載框(用於sqlite3.db文件)。 我寫了這段代碼:

#!/usr/bin/env python
import os
# HTTP Header
print "Content-Type:application/octet-stream; name=\"sqlite3.db\"\r\n";
print "Content-Disposition: attachment; filename=\"sqlite3.db\"\r\n\n";

# Actual File Content will go hear.
fo = open("sqlite3.db", "rb")

str = fo.read();
print str

# Close opend file
fo.close()

我遇到一個錯誤(從錯誤日志中復制),其中提到“ IOError:[Errno 2]沒有這樣的文件或目錄:'sqlite3.db'”

我也將python.py和sqlite3.db都粘貼到了/ var / www / cgi-bin /中,並且我給兩者都分配了0755 chmod。

我已經通過打印Hello world腳本進行了配置檢查。

知道我的錯誤是什么嗎? 我仍然感到困惑,我應該在哪里提供可下載文件的路徑?

HTTP標頭提早終止。 print自己寫換行符)

print "Content-Type:application/octet-stream; name=\"sqlite3.db\"\r\n";
print "Content-Disposition: attachment; filename=\"sqlite3.db\"\r\n\n";

Abobe行應為:

print 'Content-Type:application/octet-stream; name="sqlite3.db'
print 'Content-Disposition: attachment; filename="sqlite3.db'
print

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM