Download CGI

R

rodmc

Hi,

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?

Best,

rod
 
G

Gabriel Genellina

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top