Hello all,

Please could someone point me in the right direction...

I need to develop some code in a Joomla component where by a file can be downloaded by only one user - so it is restricted by the user ID of the logged in user.

If the user is not the user authorised to download the file in question then they may not download the file, even if the have a direct link for it.

What's the best way to go about this?

Even the smallest little pointer would be of superb help.

Thanks in advance.

Jamie

Views: 9

Replies to This Discussion

remository might be worth checking out.
Thank you for so much for your your replies.
This is a completely custom development.
I am well aware of the getUser method but the part thats baffling me is this:
If someone who has the right to download the file is given the link to the file in this way, what is to stop them from passing it to someone else? I need to make sure that only the authorised user has access to the file, even if they pass the link on to someone else.
I know of 2 methods to get round this:

1.)Store the files in (for example) media/restricted_downloads, and put a .htaccess file in there that denys from all. Then once you have done you acl, read the file, and send it to the browser, eg something like:

header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($filePath);
flush();

2.)Same thing, but store the files above the webroot.
Genius! I knew it would have something to do with that head content thing. Thanks mate, I'll give it a go right a way

Matt Thomson said:
I know of 2 methods to get round this:

1.)Store the files in (for example) media/restricted_downloads, and put a .htaccess file in there that denys from all. Then once you have done you acl, read the file, and send it to the browser, eg something like:

header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($filePath);
flush();

2.)Same thing, but store the files above the webroot.
I think it would be easier to store the file directly in the database. Your component check if that user has the right to download the file and send it to the browser. That way you don't have to mess with a htaccess file or a directory outside your joomla site.
I think there is a scalability problem with files in the database. I back up my site files manually once a month or so, but I have my database emailed to me once every week. I can do this becuase my database is only 10MB. If my database has 100 files in it, and is 500MB, I can't easily back up the database.
Great question - @Matt Thomson - thanks for that answer. MUCH appreciated!
I made my own little component to download files from a secure location (http://www.ignitejoomlaextensions.com/component/option,com_idownloa...), it is only one file (no admin interface, but if you want, I can post it somewhere.
Yes! Thanks! :)

Matt Thomson said:
I made my own little component to download files from a secure location (http://www.ignitejoomlaextensions.com/component/option,com_idownloa...), it is only one file (no admin interface, but if you want, I can post it somewhere.
I attached the file (with vars specific to my server removed).
Attachments:
I get the idea - don't store files in the database! (I wasn't going to anyway)
Also, can I just add, this is the first time I have asked a development question in ATAAW and I am incredibly impressed at the time it has taken to get some really good quality responses. Massive thanks to Amy for putting this site together and everyone else for your excellent answers to my question.

...At least I think it was Amy who put it together, let me know if I'm wrong!

RSS

Badge

Loading…

© 2012   Created by Amy Stephen.

Badges  |  Report an Issue  |  Terms of Service