ilo*_*ahz 12 html python file-upload
首先,我不需要任何功能而不是上传文件.没有进度条,没有文件类型或大小检查,没有多个文件.
我想要的是最简单的HTML网页来处理上传并使用我指定的名称保存文件.
我试着用这个:
<form action="../cgi-bin/upload.py" method="post" enctype="multipart/form-data">
<input type="file" name="upload" />
<input type="submit" /></form>
Run Code Online (Sandbox Code Playgroud)
在upload.py:
#!/usr/bin/python
import os
import commands
import cgi, cgitb
cgitb.enable()
print "Content-Type: text/html"
print
print 'start!'
form = cgi.FieldStorage()
filedata = form['upload']
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将其保存在文件中,如"Beautiful.mp3".
任何身体都能帮忙吗?
虽然,实际上,我不想使用任何脚本.我只想要最基本的html页面.只有在必须有一些CGI处理程序时才会存在Python脚本.Flash不是首选.
该filedata对象将包装一个类似文件的对象,可以将其视为常规文件.基本上你会这样做:
if filedata.file: # field really is an upload
with file("Beautiful.mp3", 'w') as outfile:
outfile.write(filedata.file.read())
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用它来做任何其他事情read(),readlines()或者readline()