views:

31

answers:

1

I have a web based application which server's content to authenticated users by interacting with a soap server. The soap server has file's which the user's need to be able to download.

What is the best way to serve these files to users? When a user requests a file, my server will make a soap call to the soap server to pull the file and then it will serve it to the user via referencing the link to it.

The question is that these temporary files need to be cleaned up at some point and my first thought was this being a linux based system, store them in /tmp/ and let the system take care of cleanup.

Is it possible to store these files in /tmp and have apache serve them 
to the user?  

If apache cannot access /tmp since it is outside of the web root, potentially I could create a symbolic link to /tmp/filename within the web root? (This would require cleanup of the symbolic links though at some point.)

Suggestions/comments appreciated on best way to manage these temporary files?

I am aware that I could write a script and have it executed as a cron job on 
regular intervals but was wondering if there was a way similar to presented 
above to do this and not have to handle deleting the files? 
+1  A: 

There's a good chance that Apache can read the tmp directory, but that approach smells bad. My approach would be to have PHP read the file and send it to the user. Basically, you send out the appropriate HTTP headers to indicate what type of content you're sending and what name to use for the file, and then you just spit out the file with echo (for example).

It looks like there's a good discussion of this in another question:

http://stackoverflow.com/questions/386845/http-headers-for-file-downloads

An additional benefit of this approach is that it leaves you in full control because there's PHP between a user and the file. This means you can add additional security measures (e.g., time-of-day controls), pull the file from various places to distribute bandwidth usage, and so on.

[additional material]

Sorry for not directly addressing your question. If you're using PHP to serve the files, they need not reside in the Apache web root, just where Apache/PHP has file-system read access to them. Thus, you can indeed simply store them in /tmp and let the OS clean them up for you. You might want to adjust the frequency of those clean-ups, however, to keep volume at the level you want.

If you want to ensure that access is reliably denied after a period of time or a certain number of downloads, you can store tracking information in your database (e.g., a flag on the user to indicate that they've downloaded the file), and then check it with your download script and possibly deny the download. This effectively separates security of access from frequency of cleanup, two things you may want to adjust independently.

Hope that's more helpful....

mr. w
@mr. w yes your first few sentences is exactly how I am doing it but this does not address how to "clean-up" these files as we do not want to fill the server up with attachments that we can retrieve via soap.
Chris
Thanks for the link though, good information.
Chris