I would like to browse and select a file via HTML, python and CGI. The HTML code is the following:

<form enctype="multipart/form-data"
action="save_file.py" method="post">
<p>File: <input type="file" name="filename" /></p>
<p><input type="submit" value="Upload" /></p>

And the python code is:

import cgi, os
import cgitb; cgitb.enable()

form = cgi.FieldStorage()

# Get filename here.
fileitem = form['filename']

# Test if the file was uploaded
if fileitem.filename:
# strip leading path from file name to avoid
# directory traversal attacks
fn = os.path.basename(fileitem.filename.replace("\\", "/" ))
open('/tmp/' + fn, 'wb').write(fileitem.file.read())

message = 'The file "' + fn + '" was uploaded successfully'

message = 'No file was uploaded'

print """\
Content-Type: text/html\n
""" % (message,)

Now I would like to browse only those files with the "csv" extension. Is there a way to do that, please?

Thanks for any help!