GBFilePicker: create dynamic folders on the fly

If you need seperate folders for each page in GBFilepicker, you should take a look…

For a recent project, i need seperate upload folders for each page in GBFilePicker. You can assign them in GBFilePicker like this:

{content_module block="image" module="GBFilePicker" mode="browser" dir=':::$page_alias:::' smarty="true"}

But this will not create directories but just tries the module to point to the directory. The result is an error message in the module ("directory does not exist").

Therefore we need a helper UDT which creates the folder for us. Call it "get_page_dir" and paste the following code:

$config = cmsms()->GetConfig();
$dir = trim((isset($params['dir']) ? '/' . $params['dir'] : '') . (isset($params['page']) ? '/' . $params['page'] : ''), '/');
if(!is_dir($config['uploads_path'] . '/' . $dir))
{
@mkdir($config['uploads_path'] . '/' . $dir, 0777, true);
}
return $dir;

now we implement the udt in the above module call:

{content_module block="image" module="GBFilePicker" mode="browser" dir=':::get_page_dir dir="imagegallery" page=$page_alias:::' smarty="true"}

Our GBFilePicker will create the neccessary folder once we create a new page.

Comments