Created
October 2, 2013 04:38
-
-
Save mayli/6789210 to your computer and use it in GitHub Desktop.
Python CGI program to convert a pdf to swf, just a POC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import cgi, os | |
import cgitb; cgitb.enable() | |
form = cgi.FieldStorage() | |
if form.has_key("file"): | |
fileitem = form['file'] | |
if fileitem.filename: | |
fn = os.path.basename(fileitem.filename) | |
fn = fn.replace(' ','_') | |
open('files/' + fn, 'wb').write(fileitem.file.read()) | |
if fn.endswith('pdf'): | |
os.system("pdf2swf -bl -o files/%s.swf files/%s"%(fn,fn)) | |
message = 'the file <b>"' + fn + '"</b> was uploaded successfully, click <a href="save_file.py">here</a> to view' | |
else: | |
files = os.listdir('files') | |
file_links = '\n'.join(['<li><a href="files/%s">%s</a> </li>'%(f,f) for f in files]) | |
message = '''<html><body> | |
<h1> Files </h1> | |
<ul> | |
%s | |
</ul> | |
<hr> | |
<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> | |
'''%(file_links) | |
print """\ | |
Content-Type: text/html\n | |
%s | |
""" % (message,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
嗯 写的很好 感觉python比php要简单不少啊 还是不是所有代码?有空了解一下python~
我再查查php的响应调用的函数去~