\ControlledFolderDataExtension
Provides the extended class with the ability to use controlled upload folders. Controlled in this case means, the amount of files contained in each folder is limited to the value of ControlledFolderDataExtension::$folder_max_files. It will create subfolders named in a numeric way like 000000 to 999999.
Add this extension to a File instance
by adding this to your _config.php:
// For Clean Models this is already done in the modules _config.php
DataObject::add_extension('CleanFile', 'ControlledFolderDataExtension');
// With this configuration, ControlledFolderDataExtension::$folder_max_files will be used as
// limit and the folder will be named by the related class name ("CleanFile") in this example.
//
// You also can pass a config array to this method to override the defaults, like this:
ControlledFolderDataExtension::set_controlled_folder_for(
"CleanFile",
array(
'folderName' => "MyFolder",
'folderMaxFiles' => 23
));
This extension adds an instance function to the decorated class e.g.
$cleanFile = CleanFile::create();
// for using a controlled upload folder with default/ earlier created settings
$cleanFile->getUploadFolder();
// you can also pass a config object like:
$cleanFile->getUploadFolder(
array(
'folderName' => "MyFolder",
'folderMaxFiles' => 23
),
true // this flag determines if this config should be made permanent for later use.
);
- Author: arillo
Synopsis
- // members
- public static integer $folder_max_files = 100;
- public static string $default_folder_name = 'ControlledUploads';
- private static array $controlled_folders = ;
- // methods
- public static array get_folder_config()
- public static void set_controlled_folder_for()
- public static string find_or_make_controlled_folder()
- public static string sanitize_folder_name()
- public string getUploadFolder()
Hierarchy
Extends
- DataExtension
Members
private
- $controlled_folders
—
array
Stores class names and folder names fot setting up controlled upload folders.
public
- $default_folder_name
—
string
Default folder name - $folder_max_files
—
int
Max. file count in controlled upload folders.
Methods
public
- find_or_make_controlled_folder() — Limits the count of files in a folder to $folder_max_files.
- getUploadFolder() — Getter for the actual folder name.
- get_folder_config() — Generates a folder config with default values.
- sanitize_folder_name() — Folder name sanitizer.
- set_controlled_folder_for() — Sets up a controlled upload folder [$folderName] for a class [$className].