I'm developing a website where Administrator can upload files (in a restricted area just for administrators) and associate the files with users. When regular users login to the website they'll have a "Documents" section where they can see the files that were uploaded and associated with them.
I dug a lot online but all the information made me confused so I thought of asking you all :)
This is what I basically trying to achieve:
-
An Administrator can access a restricted area where she can upload multiple files using an upload form and for each file, she can choose with which users to associate the file.
I Want to be able to create a form and before any update occurs, to list the file names and a Multi-Select box with all the users near each filename. -
The uploaded file will be associated with one or more users and users can be associated with more than one file. i.e many-to-many relationship.
I thought of creating afile_user
pivot table so each File class can be associated with many instances of User class and vice versa. -
The name of the file should stay as the original name but there should be a possibility for duplicate names. Thus, I should create something to distinct the files and keep them unique (but still, with the same filename).
I thought of different folder names, but it will be messy in the server. -
Users should be able to access and download only files that are associated with them. They shouldn't be able to access a file which is not associated with them, neither to know of its existent. (i.e File Not Found instead of Permission Denied).
I already have an authentication implemented and I know how to create a page that is restricted only to Admin. In order to implement the files-upload and download services I thought of something like this:
- Create a
File
model, with migration and Controller - Create a
FileController@create
(the multi-file upload form view),FileController@store
(to store the files in the database),FileController@index
(handles the view where the user sees the files associated with them and can download them) andFileController@download
(responsible to download a file to an authorized user) functions inFileController
. - Create views for the above methods
- Create a
files
table in the database (via migration) to containfile_id
andfile_name
. - Create a
file_user
pivot table because of their many-to-many characteristic.
I'm struggling with implementing the content of the above, with restricting the files to the allowed users, and I'm not sure that this is the best and most-secure approach.
How would you implement this? If you have time, I'll appreciate if you'll add pieces of code for each stage so I can understand better. A simple application that implements this would be the best to learn from. So far I didn't find any online.
I would be happy to elaborate more and explain in details the pieces that weren't clear.
Thanks!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire