How to disable and enable the function for storing uploaded files in subfolders in MediaWiki
By default, the files that users upload in MediaWiki are saved in the images folder of the application. That folder is in the root MediaWiki directory on the hosting account. There's an option which controls whether the uploaded files should be arranged and put in subfolders within the images folder, or whether they should be directly uploaded in the images folder. This option is $wgHashedUploadDirectory.
By default, the option is enabled which means that files are stored in subfolders in the images folder. When a user uploads a file MediaWiki automatically creates a folder within the images folder, and in that newly created folder it creates a subfolder in which the file is put. So each files is stored two levels down within the directory structure in relation to the images folder.
The folder and subfolder in which a file is stored are labeled using the MD5 hash value corresponding to the name of the file; MD5 is an algorithm for encrypting data. The first character of the value is used for the folder that's created within images and the first two characters are used for the name of the subfolder created within the folder. For example, if the name of the uploaded file is Example File.jpg, MediaWiki will create a folder that may be labeled 9 and within it a folder 9a, so that the path to the file within the images folder will be images/9/9a/Example File.jpg. You can view the path to a file by going to its description page and opening the file/image by clicking on it. Then just check the URL address.
The reason for storing files in subfolders is mainly for performance reasons. If all the files are stored in one folder and it's a big site with many uploads, this may affect the performance.
If you want the files to be stored directly in the one folder (e.g. the images folder), you can do this by disabling the option $wgHashedUploadDirectory. Note however that it's not recommended to change the configuration of the option once there are uploaded files. Otherwise, this will cause errors on the site. For example, images that were uploaded before the option was changed will not be displayed. This can be fixed by transferring the images (and other files) from the subfolders and putting them directly in the "images" folder, or simply by enabling the option $wgHashedUploadDirectory again.
You can disable the option by adding the following on a new line at the end of the LocalSettings.php file of your MediaWiki:
$wgHashedUploadDirectory = false;
In this way when a user uploads a file Example File.jpg, the path to it in relation to the images folder will be images/Example File.jpg.
If you want to make sure the option is enabled, just check that there's no such line in LocalSettings.php. If there is, either set it to true or delete it.
You may also find useful the following articles in our knowledge base related to uploads and images:
Was this answer helpful?
- How to capitalize and make uppercase page titles and subheadings in MediaWiki
- How to combine the links for logging in and creating accounts in MediaWiki
- How to remove preconfigured user groups in MediaWiki
- How to set and change the minimal password length for user accounts in MediaWiki
- How to display messages on the forms for editing and creating pages in MediaWiki