Grouping Files with File Sets

File Sets are a useful way to organize files in Concrete CMS. A single file can be in multiple File Sets. The file manager interface provides ways to filter by file sets, and developers can work with them through code easily as well. Adding a file to a file set programmatically is easy:

$file = \Concrete\Core\File\File::getByID(1);
$set = \Concrete\Core\File\Set\Set::getByName('My File Set');
$set->addFileToSet($file);

Removing a file from a set is similar simple:

$set->removeFileFromSet($file);

Creating a File Set Programmatically

Sometimes you want to create a file set programmatically. For example, you're creating a custom package and you want all files of a certain type added to a particular file set. Creating a file set programmatically is easy:

$set = \Concrete\Core\File\Set\Set::createAndGetSet(
    'My File Set', 
    \Concrete\Core\File\Set\Set::TYPE_PUBLIC
);

The File Set object has a few more API methods that might be useful.

API

These are just a few examples of what can be done with the Concrete File API. Get more from the Page API docs:

File Set API Reference