【发布时间】:2012-06-07 23:20:51
【问题描述】:
我确实搜索了大约 50 个相关页面,但从未见过与我的问题类似的问题。当我按下提交按钮时,它调用脚本,但脚本返回一个空页面,我看到没有上传任何文件。我的代码中没有输入错误,我检查了几次,我真的需要为我的项目运行这段代码。可能是什么问题?我在 ubuntu 下运行 apache,我的代码是:
html代码:
<html><body>
<form enctype="multipart/form-data" action="save_file.py" method="post">
<p>File: <input type="file" name="file"></p>
<p><input type="submit" value="Upload"></p>
</form>
</body></html>
python 代码:
#!/usr/bin/env python
import cgi, os
import cgitb; cgitb.enable()
try: #windows needs stdio set for binary mode
import msvcrt
msvcrt.setmode (0, os.O_BINARY)
msvcrt.setmode (1, os.O_BINARY)
except ImportError:
pass
form = cgi.FieldStorage()
#nested FieldStorage instance holds the file
fileitem = form['file']
#if file is uploaded
if fileitem.filename:
#strip leading path from filename to avoid directory based attacks
fn = os.path.basename(fileitem.filename)
open('/files' + fn, 'wb').write(fileitem.file.read())
message = 'The file "' + fn + '" was uploaded successfully'
else:
message = 'No file was uploaded'
print """\
Content-Type: text/html\n
<html><body>
<p>%s</p>
</body></html>
""" % (message,)
【问题讨论】:
-
我不知道在哪里可以找到 python cgi 中的错误日志,你能帮我吗?
-
无论您的网络服务器将它们放在哪里。
-
我正在使用 apache。默认日志文件在哪里?