我在yii2框架中使用这个模块,但无法设置正确的URL。https:/github.comsimialbiyii2-elfinder。
'connectionSets' => [
'default' => [ // like elfinder roots
[
'class' => 'simialbi\yii2\elfinder\ElFinderConfigurationLocalFileSystem',
'path' => '@webroot/uploads',
'URL' => '@web/file/files' // HERE PROBLEM
]
]
],
我是这样定义URL的 'URL' => '@web/file/files'
哪儿 file
是我的控制器和 files
是我的动作。能否请你让我知道这个URL到底是如何显示在yii2基本模板传递。
127.0.0.1:8080/project/elfinder/proxy/index?baseUrl=QHdlYi9maWxlL2ZpbGVz&path=/NewFolder/file_example_PNG_500kB.png&_t=1587811929
URL
指向存储文件的web目录(所以这和之前的目录一样 path
但作为从网络上可见的URL)。) 在你的情况下,它可能应该是 @web/uploads
.
我只是想明白了。第1步:-你需要正确设置URL管理器
'urlManager' => [
'controller/action/<file:.*>' => 'controller/action',
]
步骤2:- 创建一个动作并添加以下代码。
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";
}