How to map uploaded files to users?


I have written a script so that an admin can upload files onto the server. What I would like to have is that when users log in, they can see files depending on their user name (the admin assigns the user name specifically).
Like so:
Admin uploads files 1,2,3,a,b,c.
Admin assigns file 1 and c to user_1; file 2 to user_2; and files 3,a and b to user_3.
User_1 logs in and gets a list with file 1 and c.
User_2 logs in and gets a list with file 2.
User_3 logs in and gets a list with file 3, a, and b.

How would I do that? My problem right now is that I don’t really know how to link the filename to the user in mysql.
Thanks for any advice

How is your database currently structured? There are lots of options - but personally what I would do is:

  • Have a table that stores files (id, filename, title, etc)
  • Have a table that stores users (id, username, email, password, etc)
  • Have a table to link the file to the user (file_id, user_id)

Create a database table for file uploads. Add a record to the database with the filename, upload userid, and assigned_to_userid every time someone uploads a file. This way you can easily pull files uploaded by “upload_userid” or files assigned to “assigned_to_userid”