doonot doonot - 3 months ago 31
PHP Question

Images are not saved into the photo_dir folder using cakephp-upload plugin on CakePHP 3.2

I am using the cakephp-upload plugin and I managed to upload images to my server:


public function initialize(array $config)


$this->addBehavior('Josegonzalez/Upload.Upload', [
'avatar' => [
'fields' => [
'dir' => 'photo_dir'


echo $this->Form->create($newWorker, ['type' => 'file']);
echo $this->Form->input('avatar', ['type' => 'file']);
echo $this->Form->input('photo_dir', ['type' => 'hidden']);

Now the avatar images are uploaded, but they are not put into the photo_dir subdirectory.

enter image description here

What am I missing? It works without any problems in my CakePHP 2.8.x application.


Author of the plugin here.

The fields.dir attribute does not state what the subdirectory should be. It is a reference to the column in your database table where we should save the director where we saved the file.

If you want to change the place where you save files on disk, you should instead use the path option. Here is an example where i use the photo_dir subdirectory:

$this->addBehavior('Josegonzalez/Upload.Upload', [
    'avatar' => [
        'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}photo_dir{DS}'

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