CGI script to count downloads

Gilles Lenfant glenfant.nospam at bigfoot.com
Tue Apr 3 05:41:24 EDT 2001


Isn't it easier to include this count in a more general site statistics
features that parses your web server's log (eg use some kind of Webaliser).

Gilles

"Greg Ewing" <greg at cosc.canterbury.ac.nz> a écrit dans le message news:
3AC95ECE.B8F5E93E at cosc.canterbury.ac.nz...
> I'm trying to write a script that will keep a count
> of the number of times a file is downloaded. So far,
> the script just takes the name of the required file,
> opens the file, and passes on its contents.
>
> It works fine, except for one annoying thing:
> When Netscape pops up the box requesting a file
> name for saving, the default filename seems to be
> constructed in a screwy way from parts of the
> URL. For instance, if the URL used to retrieve the
> file is
>
>   download.py?file=download/akaroa2.6.1doc.tar.gz
>
> then the default filename that Netscape gives me
> is
>
>   akaroa2.6.1doc.tar.py
>
> So, my question is, can I put anything in the
> headers of the response to give the browser a
> hint as to what name the file should be saved
> under?
>
> Or is there a better way of going about this
> whole counting business?
>
> This is the script I'm using:
>
>   #!/usr/local/cosc/bin/python
>   print "Content-Type: compressed/gzip"
>   print
>   import cgi, sys
>   form = cgi.FieldStorage()
>   path = form["file"].value
>   f = open(path)
>   sys.stdout.write(f.read())
>   f.close()
>
> --
> Greg Ewing, Computer Science Dept, University of Canterbury,
> Christchurch, New Zealand
> To get my email address, please visit my web page:
> http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list