ResourceSpace file storage (filestore)

ResourceSpace stores resource files in obfuscated folder paths on the server and not in the database.

The folders are not meaningful to an administrator browsing the folders on the server because they are derived from the unique resource ID and are not related in any way to metadata or collections that the resources belong to.

The files are normally located in a directory named 'filestore' located in the root of your ResourceSpace root folder, although there are a number of configuration options that can alter this (e.g. $storagedir and $originals_separate_storage).

Understanding the filestore layout

The file and folder structure of the filestore is derived from a combination of the resource ID and a unique key appended to each folder containing resources. Every resource has a dedicated folder for its original file, previews and alternative files. 

Assuming that the config option $filestore_evenspread is enabled the full path of each resource is equivalent to the reverse of the resource ID with each digit in the ID corresponding to a folder.

For example, the files for resource ID 12345 would be found in the folder filestore/5/4/3/2/1_XXX where XXX would be a random string of characters (e.g. 72c804af4d2c988). The files for resource ID 345 would be found in filestore/5/4/3_XXX, the last folder in the sequence has the underscore and random characters. 

The folders for the first 9 resources (IDs 1 - 9) are found in the root of the filestore folder, for example filestore/1_852ea5db9657371, filestore/2_6f2ea289b5d89b1, filestore/3_455ca9b7730b3a8 etc. All other resources are found within the other folders filestore/0, filestore/1 etc. 

Configuring the filestore location

On a Unix system you can change the location of the filestore by simply creating a symbolic link named 'filestore' in the root of your ResourceSpace installation that points to another folder on the server. This folder could be on a network drive as long as it has been mapped to the server correctly and can be accessed by the web server user (e.g. www-data).

On a Windows system it may be easier to use the config options $storagedir and $storageurl instead. For example:


Alternatively, simply create a junction symbolic link between the two filestore locations. For example:

mklink /j C:\inetpub\resourcespace\filestore D:\filestore   

Filestore even spread

Historically resources have been distributed in an uneven fashion throughout the filestore. Resources with IDs beginning with 1 will be located below filestore/1, resources beginning with 2 will be located under filestore/2 etc. As a result most systems have a far greater number of resources located in the lower numbered folders and this has made it difficult for server administrators to separate the filestore in order to spread it over a number of drives.

ResourceSpace allows you to change this by setting the configuration option below. This will effectively reverse the path required to reach the files and will be enabled by default for new installations.

$filestore_evenspread = true;

To ensure that existing resource files are still accessible :-

  1. Set the configuration option below
  2. Run the following PHP script from a terminal or command prompt on the server. This will move the resource files into the new locations. Amend the actual command as necessary to suit your specific server configuration
    php /var/www/pages/tools/filestore_migrate.php

Separate storage for original and preview files

By enabling the config option $originals_separate_storage and running the script at pages/tools/filestore_separation.php the filestore will be split into two folders - "original" and "resized". Original uploaded resource files will be stored in the "original" folder while the preview files generated for that resource will be stored in the "resized" folder.