简体   繁体   中英

Cakephp3 create file not possible

I'm trying to create a Controller by a script, but I can't write inside the Controller folder.

I have tried with Folder class but seems it doesn't work correctly.

This is my code:

        $dir = new Folder();
        $dir->chmod(APP.'Controller', 0777, true);

        $content = '<?php 
        namespace App\Controller;

        use Cake\Core\App;
        use Cake\Utility\Security;
        use Cake\ORM\TableRegistry;

        class TestController extends AppController
        {   
            public function initialize()
            {
                $this->loadComponent(\'Flash\');
            }
        }
        ?>';

        $path = APP.'Controller/TestController.php';
        $fp = fopen($path, 'w+') or die("Unable to open file!");
        fwrite($fp, $content);
        fclose($fp);

Always return me failed to open stream: Permission denied, Unable to open file! .

Seems that command chmod doesn't work.

I think that can be a problem of owner folder but in the class Folder there isn't command chown and I need to do it inside this script not with console

How can I solve?

Thanks

The user under which the script is running has probably no permissions to change the other folder. So put them in the same group or grant the user who runs the script the required permissions.

Also, why aren't you using the bake shell ? It will do what you try to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM