File management in Moodle
This section is all about files: how to access them, how they are organized in folders, how to upload them, how to configure private files, the difference between copying and linking, file types, increasing the upload file limit, and how to deal with deleted files via the recycle bin. This is a lot to take in, so let’s get started.
Dealing with files in web-based applications is not always straightforward. While Moodle provides a user interface to perform this task, it is sometimes necessary that, as the administrator, you will have to bypass this mechanism and use other means. First, let’s look at the built-in file handling that students and teachers also use.
Moodle file management interface
Moodle offers a basic file management interface that lets you upload, move, delete, and rename files and directories. It is also possible to copy or link to files from third-party services such as Dropbox; on the same note, Moodle isn’t a content management system.
We have already talked about how Moodle stores files at the system level—the ones we shouldn’t touch! At the application level, it arranges files according to Moodle’s structure:
Important note
In Moodle, a file is always connected to the particular bit of Moodle that uses it.
Figure 2.10 – Moodle files
Files are organized in a tree-like structure, which has three types of main branches:
- Categories/Courses/Activities and Resources
- Users (private files and personal backups)
- Site home (Moodle’s front page)
We will be dealing with all those concepts at later stages, so, for now, let’s just take them for granted. Courses are arranged in categories (and subcategories) and consist of activities and resources, and there are usually further subdirectories inside activities and resources.
There are multiple users on your system, each with a dedicated file area that can be accessed from anywhere in Moodle, but there is only a single Site Home. Remember, a file is always connected to the particular bit of Moodle content that uses it, reflected by the directory-like structure:
Figure 2.11 – Moodle folders
Now that we know how files and folders are organized, let’s look at how to upload data and create directories.
Uploading files
Uploading files usually takes place via drag and drop. While this feature is vital for learners and trainers, as an administrator, you will also have to upload files from time to time, for instance, uploading users in batch mode via a CSV file.
Adding single or multiple files is straightforward: simply select the files in your Explorer (Windows) or Finder (Mac) and drag them onto the provided area inside the dotted lines shown in the following screenshot:
Figure 2.12 – Moodle files and folders
When you click on a file once it has been uploaded, you have the option to Download or Delete the file. If the selected file is a compressed archive, you have the option to Unzip it. Additionally, meta-information about the file (name, author, license, path, icon, last modified, created, and size) is displayed at the bottom of the window, as shown in the following screenshot:
Figure 2.13 – Moodle file details
For some file operations, it is necessary to use the File picker, a tool utilized whenever files have to be added to a particular object in Moodle. A user can choose from multiple file sources, known as repositories. The File picker can be accessed using the Add… button at the top left of the files area. We will be dealing with repositories in Chapter 10, Configuring Technical Features.
Closely related to uploading files is configuring the upload limit.
Upload limit
Your site has a file upload limit set to 2 MB by default. If you need to support files larger than the 2 MB threshold, you will have to increase the limit.
In your php.ini
file (find its location using the php -i
command and locate the Loaded Configuration File
entry), modify the following two lines; <value>
represents the maximum limit (multiple input formats are supported, for example, 20M or 20971520):
upload_max_filesize = <
value>
post_max_size = <
value>
If you don’t have access to the php.ini
file, create a .htaccess
file in your main Moodle directory and add the following two lines:
php_value upload_max_filesize = <
value>
php_value post_max_size = <
value>
You will also have to increase the LimitRequestBody
parameter on some systems, usually found in the Apache httpd.conf
configuration file. You may also need to modify your database configuration, such as the max_allowed_packet
size:
Figure 2.14 – Moodle upload limit
Once these changes have been applied, ensure the Maximum upload file size parameter under Site administration | Security | Site security settings has been set to Site upload limit. You can also change the user quota for private files via the Private file space parameter. When changing these two values, bear in mind that they will potentially impact the bandwidth and disk space, respectively.
For very large files such as high-quality learning resources, it would be helpful to be able to upload the content via (secure) FTP and then use the built-in unzip functionality in the File picker. However, it is not possible to upload files directly via FTP. Instead, you have to make use of the filesystem repository, which will be discussed in detail in Chapter 10, Configuring Technical Features.
Now that you are familiar with uploading files, let’s deal with personal files that belong to individual users.
Private files
Every user has an area where personal files can be stored and managed. These are only visible to the user to whom the private files belong. Any item stored in this protected area can be used throughout the site. Private files can be accessed via the File picker, the Private files block, or directly via the Private files link in the user menu:
Figure 2.15 – Moodle File picker
Handling files and directories is identical to handling other files. However, you might have spotted the Link icon in the PDF file in the preceding screenshot, which leads us nicely to the following subsection.
To link or to copy?
By default, files in Moodle are copied. When you add a file from a source (for instance, your computer or your private files), it will be copied, which means that the source and the resulting file will be logically separated. For example, if you have stored an image in your private files and you use this in three different courses, there are three logical copies. The three images will not be affected if you change the source in your private files.
Moodle also supports linking files, also known as file aliases. Let’s stick to the same example, but this time round, the three images are linked. If the source is changed, the three files in the courses will also have changed. Beware that there are some access restrictions with linked files; for example, instructor A might not be able to link to instructor B’s file.
When you select a file from a source (repository) that supports linking, an option is provided to Link to the file:
Figure 2.16 – Moodle files – copy and link
Moodle keeps track of linked files and guarantees that inconsistencies cannot occur:
- When deleting a linked file, copies of the file will be created for each link
- When a linked file is overwritten, all links are updated
- When a file overwrites a link, the files are “separated”
Linking and copying are about how files are being dealt with internally; next up are file types, which dictate how they are dealt with when users download them.
File types
Moodle does not restrict which types of files users can upload, for instance, an assignment in a course. Moodle comes with predefined values for the most popular file types in terms of the icon displayed and the program that will be opened, for example, PDF files or PowerPoint documents. However, as depicted in the following screenshot, you can add new file types and view, modify, and delete existing file types by going to Site administration | Server | File types:
Figure 2.17 – Moodle file types
When you add a new file type via the button at the bottom of the screen, you must provide the file’s Extension and its MIME type. Furthermore, you have the option to select File icon, Type groups (such as image or document), Description type, Custom description (if Description type is Custom description specified in this form), Alternative language string (if selected in Description type) and Default icon for MIME type.
So far, we have covered how files are stored, organized, and added to Moodle. Now, let’s look at what happens when files are deleted (by accident).