【发布时间】:2013-04-12 01:49:29
【问题描述】:
客户端有一个包含文本和文件的简单表单:
<form name="add_show" id="add_show" action="" method="GET">
<label class="text-info">Show Name:</label>
<input type="text" id="show_name" name="show_name" placeholder="My Show Name" required><br><br>
<label class="text-info">Show's File (JSON):</label>
<input type="file" id="file" name="file" required><br><br>
<p><input class="btn btn-danger btn-small" name="button2" value="Add the Show!" onClick="addFullShow(this.form)"></p>
</form>
使用 Javascript,我将数据发送到服务器的 Python CGI 脚本:
function addFullShow(form) {
alert("about to send form");
var formElement = form;
formData = new FormData(formElement);
var xhr = new XMLHttpRequest();
xhr.open("POST", "myScript.cgi");
xhr.send(formData);
}
在服务器端 Python CGI 脚本中,我有字段存储 fs = cgi.FieldStorage(),并且我知道如何获取文本值,即 fs['key'].value。
如何保存上传到磁盘的文件?
我希望我已经足够清楚了。谢谢!
【问题讨论】:
标签: javascript python html cgi