PHPackages                             titledk/silverstripe-uploaddirrules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. titledk/silverstripe-uploaddirrules

ActiveSilverstripe-module[Utility &amp; Helpers](/categories/utility)

titledk/silverstripe-uploaddirrules
===================================

Rules and utilities to keep the SilverStripe assets directory tidy

1.0.x-dev(11y ago)88054[1 issues](https://github.com/titledk/silverstripe-uploaddirrules/issues)1PHP

Since Nov 11Pushed 10y ago3 watchersCompare

[ Source](https://github.com/titledk/silverstripe-uploaddirrules)[ Packagist](https://packagist.org/packages/titledk/silverstripe-uploaddirrules)[ Docs](https://github.com/titledk/silverstripe-uploaddirrules)[ RSS](/packages/titledk-silverstripe-uploaddirrules/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (1)

Upload Dir Rules
================

[](#upload-dir-rules)

*by title.dk/Anselm Christophersen*

Rules and utilities to keep the SilverStripe assets directory tidy.

By installing this module and adding extensions to the objects you want affected, these objects will receive an associated folder inside of assets. Now instead of bluntly uploading everything to `assets/Uploads` your site will upload files more controlled - defaults are set, which are easy to override.

Each object's folder can subsequently easily be changed through the admin, which allows for sophisticated files &amp; assets strategies.

[![Administration](docs/img/admin.png)](docs/img/admin.png)

**Upload rules are enforced both when uploading through an upload field, but also when uploading through the text editor***(thanks to the `AssetsFolderAdmin` extension)*

This is especially helpful when working with [Subsites](https://github.com/silverstripe/silverstripe-subsites/)(we're specifically catering for those with `SubsitesUploadDirRules`), but also helpful in general, or when needing a basic [gallery](https://github.com/titledk/silverstripe-gallery), a downloads page, or anything else where you wont' want your files scattered all over the place.

Basic rules
-----------

[](#basic-rules)

The basic rules are defined in `UploadDirRules::calc_base_directory_for_object()`, basically putting all files related to `DataObject` into a `dataobjects` folder, everything related to `SiteTree` into a `pages` folder and everything related to `SiteConfig` into a `site` folder.

Overriding default upload dir rules
-----------------------------------

[](#overriding-default-upload-dir-rules)

Just implement the `UploadDirRulesInterface`. Customization through SilverStripe's config is planned, send a pull request if you need it!

Rules can be anything, from just being a common folder to containing id and or title.

### Example

[](#example)

```
// Create directory based on the page name
function getCalcAssetsFolderDirectory() {
    if ($this->ID) {
        $filter = URLSegmentFilter::create();
        return $filter->filter($this->Title);
    }
}
function getMessageSaveFirst(){
    return 'Please pick a name and save to create corresponding directory';
}
function getMessageUploadDirectory() {
    return null;
}
// Make sure that the directory is NOT saved before a page name has been chosen
function getReadyForFolderCreation() {
    if ($this->Title != 'New ' . self::$singular_name) {
        return true;
    }
}
```

Planned enhancements
--------------------

[](#planned-enhancements)

- method that lists all rules for printing or display, alseo those set via `UploadDirRulesInterface` e.g.
    - pages: `/my-subsite/pages/`
    - siteconfig: `/my-subsite/site`
    - etc.
- method that lists all objects and their asset folders
    - mainly for review / checking up, will probably be used on `UploadDirRulesTestTask`

Unit tests
----------

[](#unit-tests)

This module will contain unit tests. Run like this:

```
vendor/bin/phpunit uploaddirrules/tests

```

Make sure that you've got `phpunit` set up:

```
composer require --dev "phpunit/phpunit:*@stable"

```

Test task
---------

[](#test-task)

```
php ./public/framework/cli-script.php /UploadDirRulesTestTask

```

add ` flush=1` for first run...

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4122d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/13746b594daa08825bdaeea495edaa9e8868cb9e352f929e0c617e72b4cbde70?d=identicon)[titledk](/maintainers/titledk)

---

Top Contributors

[![anselmdk](https://avatars.githubusercontent.com/u/1316533?v=4)](https://github.com/anselmdk "anselmdk (41 commits)")[![phillprice](https://avatars.githubusercontent.com/u/320214?v=4)](https://github.com/phillprice "phillprice (1 commits)")

---

Tags

silverstripeassetssubsites

### Embed Badge

![Health badge](/badges/titledk-silverstripe-uploaddirrules/health.svg)

```
[![Health](https://phpackages.com/badges/titledk-silverstripe-uploaddirrules/health.svg)](https://phpackages.com/packages/titledk-silverstripe-uploaddirrules)
```

###  Alternatives

[silverstripe/subsites

Run multiple sites from a single SilverStripe install.

65392.9k20](/packages/silverstripe-subsites)[dorsetdigital/silverstripe-enhanced-requirements

Enhanced requirements for Silverstripe

117.8k4](/packages/dorsetdigital-silverstripe-enhanced-requirements)[twohill/silverstripe-homepagefordomain

Allows to designate a page anywhere in the tree as the homepage for a specific domain, overruling the usual homepage (which is identified by the 'home' URLSegment).

131.3k](/packages/twohill-silverstripe-homepagefordomain)[silverstripe/multi-domain

Allows multiple domains to access one CMS instance, mapping them to different sections of the hierarchy

141.6k](/packages/silverstripe-multi-domain)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
