How to set URL for elfinder in yii2?

824 Views Asked by At

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

2

There are 2 best solutions below

2
Yii2Developer On BEST ANSWER

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";
    }
3
rob006 On

URL point to web directory where files are stored (so this is the same directory as path, but as URL visible from web). In your case it probably should be @web/uploads.