Closed aiqbalsyah closed 7 years ago
I have two projects with cakephp different versions in a folder with the same database. example:
I use to upload plugin folder cakephp3. But I set my upload path to the folder you want to send cakephp2.
My Code: `$this->addBehavior('Josegonzalez/Upload.Upload', [ 'picture' => [ 'path' => '..{DS}app{DS}webroot{DS}user{DS}picture{DS}{primaryKey}', 'transformer' => function (\Cake\Datasource\RepositoryInterface $table, \Cake\Datasource\EntityInterface $entity, $data, $field, $settings) { $extension = pathinfo($data['name'], PATHINFO_EXTENSION); $tmp = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension; $tmp_2 = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension; $tmp_3 = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension;
$imagine = new \Imagine\Gd\Imagine(); $imagine ->open($data['tmp_name']) ->resize(new Box(128, 128)) ->crop(new Point(0, 0), new Box(128, 128)) ->save($tmp); $imagine2 = new \Imagine\Gd\Imagine(); $imagine2 ->open($data['tmp_name']) ->resize(new Box(256, 256)) ->crop(new Point(0, 0), new Box(256, 256)) ->save($tmp_2); $imagine3 = new \Imagine\Gd\Imagine(); $imagine3 ->open($data['tmp_name']) ->resize(new Box(600, 400)) ->crop(new Point(0, 0), new Box(600, 400)) ->save($tmp_3); return [ $data['tmp_name'] => $data['name'], $tmp => 'thumb_' . $data['name'], $tmp_2 => 'zoom_' . $data['name'], $tmp_3 => 'medsos_' . $data['name'], ]; }, ] ]);`
And then when i trying to upload throwing error Path is outside of the defined root, path: [../app/webroot/files/user/picture/264/asian.jpg.temp], resolved: [../app/webroot/files/user/picture/264/asian.jpg.temp]
Path is outside of the defined root, path: [../app/webroot/files/user/picture/264/asian.jpg.temp], resolved: [../app/webroot/files/user/picture/264/asian.jpg.temp]
Set your filesystem.root option to something that contains the directory in which you want to upload to.
filesystem.root
https://cakephp-upload.readthedocs.io/en/latest/configuration.html
Thanks it work sir :D
I have two projects with cakephp different versions in a folder with the same database. example:
I use to upload plugin folder cakephp3. But I set my upload path to the folder you want to send cakephp2.
My Code: `$this->addBehavior('Josegonzalez/Upload.Upload', [ 'picture' => [ 'path' => '..{DS}app{DS}webroot{DS}user{DS}picture{DS}{primaryKey}', 'transformer' => function (\Cake\Datasource\RepositoryInterface $table, \Cake\Datasource\EntityInterface $entity, $data, $field, $settings) { $extension = pathinfo($data['name'], PATHINFO_EXTENSION); $tmp = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension; $tmp_2 = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension; $tmp_3 = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension;
And then when i trying to upload throwing error
Path is outside of the defined root, path: [../app/webroot/files/user/picture/264/asian.jpg.temp], resolved: [../app/webroot/files/user/picture/264/asian.jpg.temp]