Download CGI
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Oct 14 01:13:17 EDT 2008
En Sun, 12 Oct 2008 06:48:29 -0300, rodmc <userprogoogle-139 at yahoo.co.uk>
escribió:
> I am trying to figure out how to create a Python script which will
> open a file from a folder outwith the public_html path and serve it
> directly to the user for downloading. The aim being so that the users
> cannot see where the file is served from. Is there an easy way to do
> this, or an HTML header I am missing or an easy way in Python?
Just emit the right Content-Type, maybe Content-Length, and the file
contents itself.
#!/usr/bin/python
f = open("/path/to/file.jpg", "rb")
data = f.read()
f.close()
print "Content-Type: image/jpeg"
print "Content-Length: %d" % len(data)
print
print data
--
Gabriel Genellina
More information about the Python-list
mailing list