如何集成CKFinder与Laravel? [英] How to integrate CKFinder with Laravel?

查看:206
本文介绍了如何集成CKFinder与Laravel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将CKFinder与Laravel集成,我大约有95%。我可以得到一切工作,除了 CheckAuthentication 函数 - 我必须使它返回true ,无论上传工作。

I'm trying to integrate CKFinder with Laravel, and I'm about 95% there. I can get everything to work, except for the CheckAuthentication function - I have to make it return true regardless for the upload to work.

我尝试做的是在config.php文件中引导Laravel,然后检查用户是否登录,如下所示:

What I've tried doing is bootstrapping Laravel in the config.php file and then checking if a user is logged in, like below:

public / packages / ckfinder / config.php

<?php
/*
 * ### CKFinder : Configuration File - Basic Instructions
 *
 * In a generic usage case, the following tasks must be done to configure
 * CKFinder:
 *     1. Check the $baseUrl and $baseDir variables;
 *     2. If available, paste your license key in the "LicenseKey" setting;
 *     3. Create the CheckAuthentication() function that enables CKFinder for authenticated users;
 *
 * Other settings may be left with their default values, or used to control
 * advanced features of CKFinder.
 */

/** RIPPED FROM public/index.php **/

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__.'/../../../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let's turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight these users.
|
*/

$app = require __DIR__.'/../../../bootstrap/start.php';

/** END public/index.php **/

/**
 * This function must check the user session to be sure that he/she is
 * authorized to upload and access files in the File Browser.
 *
 * @return boolean
 */
function CheckAuthentication()
{
    // WARNING : DO NOT simply return "true". By doing so, you are allowing
    // "anyone" to upload and list the files in your server. You must implement
    // some kind of session validation here. Even something very simple as...

    return Auth::check();
}

这总是返回false。我也试着直接使用Laravel的 Session 在有人登录时将变量设置为true,当他们注销时设置为false,然后检查config.php文件中的变量,但它总是返回 Session :: get(IsAuthorized,false); 中的默认值。任何人都可以提供一些指导 -

This always returns false, though. I've also tried directly using Laravel's Session to set a variable to true when someone logs in, and false when they log out, and then checking that in the config.php file, but it always returns the default value in Session::get("IsAuthorized", false);. Can anyone offer some guidance as to -

1)如何验证用户是否应该允许上传?

1) How to authenticate whether the user should be allowed to upload?


推荐答案

为什么要在另一个文件中引导Laravel会导致它使用一个单独的会话,

我尝试将simogeo的Filemanager和KCFinder集成到一个Laravel项目中,我发现了同样的问题。

I tried integrating simogeo's Filemanager and KCFinder into a Laravel project and I found the same problem.

使用这个代码,可以共享Laravel的会话和检查身份验证外部项目:

With this code, it's possible to share Laravel's session and check authentication from external projects:

https://gist.github .com / frzsombor / ddd0e11f93885060ef35

这篇关于如何集成CKFinder与Laravel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆