a guest Sep 11th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- Sample file upload form:
- <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>
- Python 3 upload script:
- 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'
- message = 'No file was uploaded'
- print('Content-Type: text/plain\n')
- print('Ciao, ' + message)
- Fails with SOME unicode characters in file name!
RAW Paste Data