FriendsOfCake / cakephp-upload

CakePHP: Handle file uploading sans ridiculous automagic
https://cakephp-upload.readthedocs.io/
MIT License
551 stars 255 forks source link

Upload Outside Directory Root Cakephp 3 #427

Closed aiqbalsyah closed 7 years ago

aiqbalsyah commented 7 years ago

I have two projects with cakephp different versions in a folder with the same database. example:

  1. www.example.com: var / www / html / cakephp2
  2. www.api.example.com: var / www / html / cakephp3

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]

josegonzalez commented 7 years ago

Set your filesystem.root option to something that contains the directory in which you want to upload to.

https://cakephp-upload.readthedocs.io/en/latest/configuration.html

aiqbalsyah commented 7 years ago

Thanks it work sir :D