Created
May 11, 2015 09:17
-
-
Save gvhung/e435df73996dbbccfa06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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