Jump to content

Secure File Download In PHP


CelticExile

Recommended Posts

Ok first off I know how to write a file download script in PHP.

 

Ok the files on my system are stored in a back side directory under a random name (for added security from webserver attacks) now I can rename them, then upload to the user using readfile().  I would then want to rename them back and close the temporary browser window(or tab) with the file download PHP in.

 

So my question is can I just put the rename code straight back in after readfile() and close the window before the user has even clicks to OK the download or do I have to wait?  My assumption was that the file once in the output buffer would no longer be linked to the local file.

 

Another question I had was, do I have to go through this renaming business or can I parse the file to the output buffer with a temporary name (similar to the upload) ?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/199682-secure-file-download-in-php/
Share on other sites

I don't know what sort of files your dealing with, but just a quick note of caution. The readfile reads the entire file into memory before sending it. If you are dealing with large files or busy servers this could soon start to cause problems.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.