Folder and file sharing in Drupal Here is what I am trying to achieve.
I have two roles Teachers and Students.

Each teacher has images of answers written by the students in an exam. After checking these papers, teacher takes an image of each answer-sheet. He names it in a certain pattern using student-id. Thus, teacher has many images (like sid-1-im1.jpg, sid-1-im2.jpg, sid-2-im1.jpg). A student can have multiple images on his name depending on how many sheets he had submitted.

I want to create a website where a teacher can create a folder for this exam, say, Economics-2017-2018. Within this folder, he can upload all images.
What would be the best way to achive this folder+multi-file upload?

Next I want to programmatically assign permissions to these uploaded images based on student id of the file name. So that, a student can view only his files.

How can this programmatic feature be achieved.

There are more features such as notifying students, ability to comment on files etc. But, I think drupal can handle them easily.

I intend to use Drupal 7 or 8 for the purpose.
You wouldn't actually need to write any custom code to implement something like this.

A possible solution is outlined below. It is aimed at Drupal 7. Some of the functionality mentioned may not be ready for Drupal 8 so you might need alternate modules or custom code in those cases.


Create a new content type, which would be named "Exam paper" or similar. There would be one node per student per exam.
Add a multiple value file field to the content type. Make sure it uses the private file system. Using the private file system will mean that only users with access to the node will be able to access the files attached to the node.
You can use the file field paths and token modules to make it so that the file directory structure and file names match the pattern you want. With the tokens you can easily reference student, teacher or exam information from fields on the node in the path or file name. This has no effect on access control but might make things better for you in other ways.
There are a number of ways you can handle access control as there are a variety of access control modules available for nodes, however I would be inclined to go with the node access user reference module. So you would add an entity reference field on the content type that references users with the student role. You can then set permissions so that the referenced user can access the node and other users cannot.
You can use the rules module to notify the user under various circumstances.
You can use Drupal core comments to have comments on exam paper nodes.
Due to using nodes you can leverage the wide variety of add on modules that focus primarily on nodes.
If you want to store additional data with each specific file, you can install the file entity module, which will allow you to add fields at the file level as well as the node level.