From b8467a090d6d8b4b05ffdca17dcde0c7f1d5a2ce Mon Sep 17 00:00:00 2001 From: simkimsia Date: Sat, 16 Jan 2016 16:25:26 +0800 Subject: [PATCH] Call the $path->basepath() function once Why? Because if you use {time} in the path variable, you may end up saving the file to a folder different than the one indicated under `dir` --- src/Model/Behavior/UploadBehavior.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Model/Behavior/UploadBehavior.php b/src/Model/Behavior/UploadBehavior.php index 9b44b3f4..adbd85f6 100644 --- a/src/Model/Behavior/UploadBehavior.php +++ b/src/Model/Behavior/UploadBehavior.php @@ -76,7 +76,8 @@ public function beforeSave(Event $event, Entity $entity, ArrayObject $options) $data = $entity->get($field); $path = $this->getPathProcessor($entity, $data, $field, $settings); - $files = $this->constructFiles($entity, $data, $field, $settings, $path->basepath()); + $basepath = $path->basepath(); + $files = $this->constructFiles($entity, $data, $field, $settings, $basepath); $writer = $this->getWriter($entity, $data, $field, $settings); $success = $writer->write($files); @@ -86,7 +87,7 @@ public function beforeSave(Event $event, Entity $entity, ArrayObject $options) } $entity->set($field, $path->filename()); - $entity->set(Hash::get($settings, 'fields.dir', 'dir'), $path->basepath()); + $entity->set(Hash::get($settings, 'fields.dir', 'dir'), $basepath); $entity->set(Hash::get($settings, 'fields.size', 'size'), $data['size']); $entity->set(Hash::get($settings, 'fields.type', 'type'), $data['type']); }