• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Protect files and use MVC structure to hand the downloads

#1
[eluser]giovannidc[/eluser]
I was wondering if it would be possible to use an MVC approach for when a user downloads a file.

So instead of the normal link "http://mysite.com/downloads/myfile.zip" that the user clicks to download the file I want to do the following:

Upload the File
-Upload my file to a folder with a unique name like "213dsa231aqs"
-Remove the extension and rename the file to something random like "34yhjdnfasd"
--If possible even encrypt the file

Create the controller
-Create a "download" controller that will have a "file" function that will accept two variables, one that will be the file id and the other, the output name of the file e.g. "download/file/34yhjdnfasd/myfile.zip"

Create the model
- So when the user clicks "http://mysite.com/download/file/34yhjdnfasd/myfile.zip" the model will then fetch the file "34yhjdnfasd" and push it back to the user as myfile.zip

So in essence, I dont want a user to have direct access to a file, I want to protect my files by letting only a logged in user be able to download them, and to manage the amount of times they allowed to download that particular file.

Is this possible? Any ideas on how to this or are there other/better ways to do this?

I don't think I can use a database for this as some files are quite big.

#2
[eluser]cristian.tantar[/eluser]
Hy,
I used this method:
On upload, i-ve changed the file name and save it somewhere on server, eg: hidden/folder/
In database, I saved the old name, the new name and location of file.
In controller, you can download the file by simply call: download/[fileid]

You can change to download/[new-random-name] and limit this download by login, etc.

Regards,
www.tantar.info


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.