Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sample file upload form:
- <html>
- <body>
- <form enctype = "multipart/form-data"
- action = "/bin/up.py" method = "post">
- <p>File: <input type = "file" name = "filename" /></p>
- <p><input type = "submit" value = "Upload" /></p>
- </form>
- </body>
- </html>
- Python 3 upload script:
- #!/usr/bin/python3
- import cgi, os
- import cgitb; cgitb.enable()
- form = cgi.FieldStorage()
- fileitem = form['filename']
- if fileitem.filename:
- fn = os.path.basename(fileitem.filename)
- open('/tmp/' + fn, 'wb').write(fileitem.file.read())
- message = 'The file "' + fn + '" was uploaded successfully'
- else:
- message = 'No file was uploaded'
- print('Content-Type: text/plain\n')
- print('Ciao, ' + message)
- Fails with SOME unicode characters in file name!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement