I am creating a members-only script where they log in and click on links to load their files. The trick is, the user may never know where the real files are so they can't just hotlink or give it to their friends.
My original idea was to copy the original file and put it in a /temp/ folder with a random name. Then once they click on the link and load the file, the file would be removed from the temp folder.
The problems with this seem costly; the overhead of copying the file into memory to transport it over to another folder on the server and THEN let the load it doesn't seem worth it. Especially if these files ever get larger than 10MB.
I need to hear your ideas on how I can load a bunch of links (the original files are stored as absolute paths in my mysql database) so when a user sees or clicks the links they will NEVER see where the original file came from but they'll still be able to load it in their browser.
I asked this on another site and got the following two answers which I didn't understand. So if you think these will work, could you try re-explaining it?
Thank you!
My original idea was to copy the original file and put it in a /temp/ folder with a random name. Then once they click on the link and load the file, the file would be removed from the temp folder.
The problems with this seem costly; the overhead of copying the file into memory to transport it over to another folder on the server and THEN let the load it doesn't seem worth it. Especially if these files ever get larger than 10MB.
I need to hear your ideas on how I can load a bunch of links (the original files are stored as absolute paths in my mysql database) so when a user sees or clicks the links they will NEVER see where the original file came from but they'll still be able to load it in their browser.
I asked this on another site and got the following two answers which I didn't understand. So if you think these will work, could you try re-explaining it?
Thank you!
Code:
Why do you insist on copying the files? Why not store the random file names (and the real file name) in some sort of database and open the real file (and send that one) when a person makes a request for a random file? (And after the request remove the random file from the DB)
Code:
Generate a new unique key for each user who needs to access a file. Store this in a database of some sort that associates that particular key with the name of the file to serve. This can be a flat file (but watch out for locking!), a tied hash (fast and reasonably easy to set up), or a relational database (probably overkill unless you're already using one).
Instead of redirecting the user to a temporary file with a randomly-generated name, redirect the user to another CGI program that takes in the unique key, looks up the appropriate file in the database, then serves the file to the user.
Bonus tip: look into the Content-Disposition header to set the filename appropriately.