CoCalc Shared Fileswww / cgi-bin / superstein / upload.pyOpen in CoCalc with one click!
Author: William A. Stein
1
#!/usr/bin/python
2
3
# mdb_table.py
4
# William Stein, August 13, 2003
5
6
DIRECTORY="/superstein/upload/"
7
8
import cgi, os, string, sys, time
9
10
print "Content-Type: text/html" # HTML is following
11
print # blank line, end of headers
12
13
form = cgi.FieldStorage()
14
15
if not form.has_key("attached_file") or len(form["attached_file"].value) == 0:
16
print "\n<h1>Error</h1>"
17
if not form.has_key("attached_file"):
18
fname = ""
19
else:
20
fname = form["attached_file"].value
21
print "The file '%s' that you specified is not valid or empty."%fname
22
print '<h2><a href=%s>Back to File Repository</a></h2>'%DIRECTORY
23
sys.exit(1)
24
25
file = form["attached_file"]
26
27
name = file.filename
28
29
fullname = "/home/%s/files/%s"%(DIRECTORY,name)
30
f = open(fullname, "w")
31
f.write(file.value)
32
f.close()
33
34
print "<p>The file '" + name + "' has been uploaded."
35
print "You may wish to confirm that the file has been"
36
print 'added to <a href="%s/files/">the file repository.</a>'%DIRECTORY
37
38
print "<br><hr>"
39
print '<h2><a href="%s">Back to file upload</a></h2>'%DIRECTORY
40