Lesson - 69 : Python Advanced - Python CGI Programming : File Upload Example

preview_player
Показать описание
Python CGI Programming : File Upload Example:
To upload a file, the HTML form must have the enctype attribute set to multipart/form-data. The input tag with the file type creates a "Browse" button.

<html>
<body>
<form enctype="multipart/form-data"
<p>File: <input type="file" name="filename" /></p>
<p><input type="submit" value="Upload" /></p>
</form>
</body>
</html>

Above example has been disabled intentionally to save
people uploading file on our server, but you can try
above code with your server.

form = cgi.FieldStorage()
# Get filename here.
fileitem = form['filename']
# Test if the file was uploaded
# strip leading path from file name to avoid
# directory traversal attacks
message = 'The file "' + fn + '" was uploaded successfully'
else:
message = 'No file was uploaded'
print """\
Content-Type: text/html\n

Рекомендации по теме
welcome to shbcf.ru