phpyii2yii-extensionsyii2-basic-appelfinder

How to set URL for elfinder in yii2?


I am using this module in yii2 framework but unable to set the correct URL https://github.com/simialbi/yii2-elfinder

 'connectionSets' => [
                'default' => [ // like elfinder roots
                    [
                        'class' => 'simialbi\yii2\elfinder\ElFinderConfigurationLocalFileSystem',
                        'path'  => '@webroot/uploads',
                        'URL'   => '@web/file/files' // HERE PROBLEM
                    ]
                ]
            ],

This is how I have defined URL 'URL' => '@web/file/files' where file is my controller and files is my action . Could you please let me know how exactly this URL show be passed in yii2 basic template .

127.0.0.1:8080/project/elfinder/proxy/index?baseUrl=QHdlYi9maWxlL2ZpbGVz&path=/NewFolder/file_example_PNG_500kB.png&_t=1587811929


Solution

  • I just figured it out . Step 1 :- You need to set the URL managers properly

     'urlManager' => [
      'controller/action/<file:.*>' => 'controller/action',
    ]
    

    Step 2 :- Create an action and add this code

    public function actionYourActionName($file)
        {
            $image_path = YOUR_UPLOAD_PATH . basename($file);
            if (file_exists($image_path)) {
                return \yii::$app->response->sendFile($image_path, $file, [
                    'inline' => true //OPTIONAL
                ]);
            } 
             return "What exception you want to throw";
        }