Upload Plugin: How to configure upload path


I’m using CakePHP Upload plugin. Currently, the configuration is set as follow:

$this->addBehavior('Josegonzalez/Upload.Upload', [
	'poster' => [
		'fields' => [
			'dir' => 'poster_dir', // defaults to `dir`
			//'size' => 'photo_size', // defaults to `size`
			//'type' => 'photo_type', // defaults to `type`
	'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}{field-value:slug}',

I can upload the image. However, in the poster_dir column, the input is something like:


What I need is to store only the {field-value: slug} in the poster_dir, not the whole path. I tried to remove the path as follows:

'path' => '{field-value:slug}',

The output is as expected, only {field-value: slug} is recorded into poster_dir, but the file is uploaded at the root directory, not in the webroot/files/Articles directory.

How can i capture the {field-value:slug} into the poster_dir and the file is uploaded into …webroot/files/{model}/{field-value:slug}


you can substring the path info you dont need out of it when you need to use that data

Can’t you read the slug from the entity?

What I do is add a virtual in the entity that calculates the URL (I think thats what you want)

// in the entity
protected function _getUrl()
    if (!$this->id) {
        return '';
    if (!$this->poster) {
        return '';

    return Router::url("/files/model/$this->parent_id/$this->poster", true);

// in the template
echo $this->Html->link('Download file', $entity->url);

its the plugins behaviour that the path is stored into dir setting. You probably need to change the plugin and it probably also breaks the functionality that deletes files so you then also need to change it. But isn’t the slug value already saved in the slug field?

@raul338 & @thomasg

Thanks. Yes, I can access the slug field. Why I’m not thinking this solution :grimacing:

Problem solved! Thank you again.