Download CGI

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rodmc

    Download CGI

    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
  • Gabriel Genellina

    #2
    Re: Download CGI

    En Sun, 12 Oct 2008 06:48:29 -0300, rodmc <userprogoogl e-139@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

    Comment

    Working...