dongrouyuan5685 2012-05-09 12:37
浏览 40
已采纳

在具有多个用户的php / mysql应用程序中实现文件夹共享

I have a php/mysql application. There are users who have folders. Folders can only be one level deep. Each folder can have unlimited number of documents. The relevant tables are as follows:

user_table:

user_id(PK), name, password, etc

folder_table:

folder_id(PK), name, user_id(FK into user_table)

document_table

document_id(PK), user_id(FK), folder_id(FK), date, name, etc

All queries to operate on folders and documents are of the form

select/update/insert <blah, blah, bhah>
where user_id = %d

Now, I'm looking to allow users to share they folders with other users. I want to do this in the least disruptive way possible. I also want to minimize run time overheads of resulting WHERE clause.

I've been wracking my brains and googling but haven't found a simple enough solution. I can think of implementing it in a manner similar to unix's (read, write, execute) along with (owner, group, others) mechanism. But it seems a bit too complicated for my humble system.

I would really appreciate if someone could give me pointers as to which approach I could possibly take. My goals are simple:

  1. The system doesn't require a whole lot of reworking
  2. At a minimum users should be able to share folders with other users or groups (I will add concept of groups if needed)
  3. There should not be too much overhead in SQL statement's WHERE clause as opposed to what it is now (as simple as: WHERE user_id = %d)
  • 写回答

1条回答 默认 最新

  • dongpang1898 2012-05-09 12:43
    关注

    Sharing folder(s) with user(s)

    You can to add a table *folder_user* with columns folder_id(FK), user_id (FK)

    The user_id in *folder_table* represents the owner of the folder. When the owner shares this folder with another user, you add folder_id and user_id (with whom folder is shared) into folder_user table.

    Later, you can add column access (enum 'READ', 'READ_WRITE') to the same table, to see if a user is allowed to edit documents in the folder or not.

    Sharing folder(s) with group(s)

    1. You need a table group
    2. Then you need to add users to groups, so add a table *user_group* : user_id(FK), group_id(FK)
    3. Then, to give access to of a folder to a group add table *folder_group*: folder_id(FK), group_id(FK) to give access for a folder to a group.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?