Downloading file from cgi application

S

sophie_newbie

Hi,

I'm writing a cgi application in Python that generates a PDF file for
the user and then allows them to download that file. Currently I'm
just writing the PDF file to the 'htdocs' directory and giving the
user a link to this file to download it. But the problem is that
another user could simply come along and download a file that isn't
their file by typing the address into the address bar. I don't want to
delete the file after it is downloaded either because I'd like the
user to be able to download it again if necessary. Is there any way
around this problem?

Thanks.
 
J

Jeff

Store the file in a database. When an authorized user clicks the
link, send the proper headers ('Content-Type: application/pdf') and
then print the file.
 
D

Diez B. Roggisch

sophie_newbie said:
Hi,

I'm writing a cgi application in Python that generates a PDF file for
the user and then allows them to download that file. Currently I'm
just writing the PDF file to the 'htdocs' directory and giving the
user a link to this file to download it. But the problem is that
another user could simply come along and download a file that isn't
their file by typing the address into the address bar. I don't want to
delete the file after it is downloaded either because I'd like the
user to be able to download it again if necessary. Is there any way
around this problem?

If the user needs to be authenticated, yes. Just encode the username in the
pdf-name (on the FS that is, what name you give the downloaded file is
unrelated).

Then just allow to download the pdf by a user with the right name.

Diez
 
J

Jeff McNeil

You could also just store the files outside of the document root if
you don't want to worry about a database. Then, as Jeff said, just
print the proper Content-Type header and print the file out.
 
S

sophie_newbie

You could also just store the files outside of the document root if
you don't want to worry about a database. Then, as Jeff said, just
print the proper Content-Type header and print the file out.

Store the file in a database. When an authorized user clicks the
link, send the proper headers ('Content-Type: application/pdf') and
then print the file.

Thanks alot, you guys sure know your stuff!
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top