One of the major re-engineering efforts undertaken for Moodle 2.0 was a complete redesign of the Moodle file storage system. The release of Moodle 2.0 has delivered a database centric file handling model, replacing the OS file system centric model.
Moodle <= 1.9 file storage
Moodle stores files in a number of circumstances: student assignment submissions and teacher course resources being two examples. How would you store them? In Moodle 1.9 a directory structure was used to identify the files, using a combination of the course, module and user ID numbers. So, in your Moodle data directory you would see a number of folders corresponding to Moodle course ID numbers, in which you would find the course files (if any) and a ‘moddata’ folder.
The ‘moddata’ folder contains sub folders corresponding to the Moodle module types, with further sub folders corresponding to the module instance ID numbers, and yet further sub folders corresponding to the user ID numbers which contain the user uploads to that instance of that module.
Here is an example file and folder structure for a student with ID number 123 uploading an assignment submission to an assignment instance with ID number 456, in a course with ID number 789:
{MOODLEDATA}/789/moddata/assignment/5/123/my_midterm_assignment.doc
Corresponding database records are stored on a per module basis (if stored at all). Assignment submission details like submission date are stored in the database table ‘assignment_submissions’. Make sense? Perhaps, but it’s not ideal. This configuration makes backup and restoration more difficult for a start. This method also means that the same file could be stored multiple times in different parts of the Moodle data – something which is likely to happen if you copy and re-use courses from year to year.
Moodle 2.0 file storage
Moodle 2 centralises the storage of files within a {MOODLEDATA}/filedir directory and a single ‘files’ database table. A new files API has been created to provide higher level of control. All files are referenced by a record in a files table and accessed via the files API.
In the background, files uploaded into Moodle 2.0 are given an SHA1 hash value, and this hash value is used as the basis for storing the file in MOODLEDATA/filedir/HASH_PATH/HASH_FILE.
In the example {MOODLEDATA}/filedir/5c/eb/b0/5cebb03d702827bb9e25b38b06910fa5 the hashed value for the file (5cebb03d702827bb9e25b38b06910fa5) is stored in a hash path created from the first three pairs of characters in the hash value: [5c][eb][b0]3d702827bb9e25b38b06910fa5. This method of storage means the same file uploaded multiple times will only be stored once, because the hash value will be the same. Using the hash value as a basis of creating the file storage directories creates a natural distribution of the files across multiple folders. This helps reduce the possibility that any one directory will contain an excessive number of files.
There are other benefits to this file storage method; backup & restores are simplified, and all file access is through the file storage API giving better control. Additionally, the original file names are not recorded on disk which allows for full Unicode file name support, regardless of the Unicode support in the underlying operating system file system.
One possible downside is that you will no longer be able to look at the Moodle data directory and immediately understand and modify the files with ease, but should anyone be doing this anyway?
The problem with this is that makes difficult to interoperate Moodle with other applications that share the files. For example, my students were uploading files via task that were processed by third part applications
Using 1.9… After marking assignments I move examples from the moddata folder to a ‘gallery’ folder in the parent directory that links to a ‘Projects Gallery’ in the course Moodle – students cannot access the moddata folder. Will there be an easier solution for creating a ‘Projects Gallery’ in Moodle 2.0?
This wouldn’t be possible with Moodle 2. You would first have to look up the database to find the hash for the assignment, find the file, then move it to a new locate and create the correct references in the database.
I think the process you would follow in Moodle 2 would be to add a ‘Folder’ resource to the course. You then add files to that folder using the file picker interface.
The file picker is very nice, you can browse and add course files, upload files or add files from remote services (Flickr, Google docs, Picasa).
Unfortunately I don’t think you can browse the student assignment submissions from the file picker, so you might have to download the assignments then upload them to the folder resource at this time.
Hello,
When I try to upload a file via the File Picker I get this error:
Unknown exception related to local files (Invalid file path)
I’ve read that it may be an SSH issue so I changed port 7022 to port 22 on my server but did not work.
The moodledata folder and the filedir folder persmissions are set to 777
I am using Moodle 2.0.3 under a CentOS server
I have the same version of moodle running on a windows 7 computer under the xampp server and have no problems. I understand that Linux and Windows handle files and ports in a different way.
I have had problems adding language packs (not able to write md5 file). I manually created the language pack folder in order to sort out that problem.
I’m pretty sure that moodle has problems trying to connect either to the database or create folders under the moodledata/filedir folder.
If any of you know how to solve this, please send me an email.
Thank you
Hello Gabriel,
In a Unix/Linux environment the directory tree starts with / , such as /home/gabriel/www
The error you are seeing is thrown when Moodle detects that the file path does not begin with the ‘/’ character. This path is set as a field in the Moodle ‘files’ database table; I do not think it is something that is configurable. There may be a problem with your server or Moodle configuration.
Firstly I would advise that you update your Moodle code to the latest version. Then I would verify that the Moodle and server configurations are correct.
There is an open issue on the Moodle bug tracker which might be relevant – it relates to Redhat also, which might be a clue: http://tracker.moodle.org/browse/MDL-27651
Stephen