# Upload plugin: dir not create sub folder

**URL:** <https://discourse.cakephp.org/t/upload-plugin-dir-not-create-sub-folder/8204>\
**Category:** Plugins\
**Created:** [August 11, 2020, 6:11am UTC](https://discourse.cakephp.org/t/upload-plugin-dir-not-create-sub-folder/8204 "2020-08-11T06:11:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Foggies](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@Foggies](https://discourse.cakephp.org/u/Foggies)\
**Post date:** [August 11, 2020, 6:11am UTC](https://discourse.cakephp.org/t/upload-plugin-dir-not-create-sub-folder/8204/1 "2020-08-11T06:11:02Z")

</div>

I’m using CakePHP [upload plugin](https://github.com/FriendsOfCake/cakephp-upload/tree/cake-4.x) for CakePHP 4. I’ve needed to upload a poster to the project. the field is configured as ‘poster’ and ‘poster\_dir’ to store the directory.

The model has been configured:

```
$this->addBehavior('Josegonzalez/Upload.Upload', [
'poster' => [
	'fields' => [
		'dir' => 'poster_dir',
	],
],

```

]);

The form has been configured to type=‘file’. However, the poster directory will save the directory only without create a folder based on ID eg: webroot\files\Documents\poster\

I’ve used the path as shown below:

```
$this->addBehavior('Josegonzalez/Upload.Upload', [
'poster' => [
	'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}{primaryKey}',
	'fields' => [
		'dir' => 'poster_dir', 
	],
],

```

]);

it shows an error:{primaryKey} substitution not allowed for new entities

How can I solve these issues? Thanks

---

<div class="post-metadata">

**Author:** ![diep.doTMS](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@diep.doTMS](https://discourse.cakephp.org/u/diep.doTMS)\
**Post date:** [August 11, 2020, 7:31am UTC](https://discourse.cakephp.org/t/upload-plugin-dir-not-create-sub-folder/8204/2 "2020-08-11T07:31:34Z")

</div>

The default value for the `path` option is `webroot{DS}files{DS}{model}{DS}{field}{DS}` .

```auto
$this->addBehavior('Josegonzalez/Upload.Upload', [
    'poster' => [
        'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}photo_dir{DS}'
    ]
]);

```
