sunhater / kcfinder

KCFinder web file manager
http://kcfinder.sunhater.com
402 stars 209 forks source link

year/month folders #178

Open tenq opened 5 years ago

tenq commented 5 years ago

Hi, I`m try to create and automatic set a current folder based on year/month. When user open kcfinder, year/month (2019/03) folder automatic open and show images. If images, images/2019/03 if files files/2019/03.

in config.php add directive after theme to show/hide folders base on year/month: 'theme' => "default", 'uploads_use_yearmonth_folders' => true,

in core/class/browser.php, action function:

` public function action() {

   $act = isset($_GET['act']) ? $_GET['act'] : "browser";

  if (!method_exists($this, "act_$act"))
        $act = "browser";
    $this->action = $act;
    $method = 'act_'.$act;

    if ($this->config['disabled']) {
        $message = $this->label("You don't have permissions to browse server.");
        if (in_array($act, array("browser", "upload")) ||
            (substr($act, 0, 8) == "download")
        )
            $this->backMsg($message);
        else {
            header("Content-Type: text/plain; charset={$this->charset}");
            die(json_encode(array('error' => $message)));
        }
    }

    if ($this->config['uploads_use_yearmonth_folders'])
    {

        // settings to year/month folders // estra code
        if ((!isset($this->session['dir']) ||
        (isset($this->session['dir']) && $this->session['dir'] == $this->type && (!isset($_POST['dir'])))))
        {

            $dir = $this->postDir();
            //setting the year
            $y = date('Y');
            $newYear = $this->normalizeDirname(trim($y));

            if (!file_exists("$dir/$newYear")) {
                if (!mkdir("$dir/$newYear", $this->config['dirPerms'])) {
                    $this->errorMsg("Cannot create {dir} folder.", array('dir' => $this->htmlData("$dir/$newYear")));
                }
            }

            $m = date('m');
            $subdir = "$y/$m";

            //$newDir = $this->normalizeDirname(trim($subdir));
            //$newDir = str_replace('_','/',$newDir);
            $newDir = trim($subdir);

            if (!file_exists("$dir/$y/$m")) {
                if (!mkdir("$dir/$newDir", $this->config['dirPerms'])) {
                    $this->errorMsg("Cannot create {dir} folder.", array('dir' => $this->htmlData("$dir/$newDir")));
                }
            }

            $this->session['dir']  = $this->type . '/' . $newDir;
        }
        else {
            $type = $this->getTypeFromPath($this->session['dir']);
            $dir = $this->config['uploadDir'] . "/" . $this->session['dir'];

            if (($type != $this->type) || !is_dir($dir) || !is_readable($dir))
                $this->session['dir'] = $this->type;
        }

    } else { //default
        if (!isset($this->session['dir']))
            $this->session['dir'] = $this->type;
        else {
            $type = $this->getTypeFromPath($this->session['dir']);
            $dir = $this->config['uploadDir'] . "/" . $this->session['dir'];
            if (($type != $this->type) || !is_dir($dir) || !is_readable($dir))
                $this->session['dir'] = $this->type;
        }
    }

    //end extra code
    $this->session['dir'] = path::normalize($this->session['dir']);

    // Render the browser
    if ($act == "browser") {
        header("X-UA-Compatible: chrome=1");
        header("Content-Type: text/html; charset={$this->charset}");

    // Ajax requests
    } elseif (
        (substr($act, 0, 8) != "download") &&
        !in_array($act, array("thumb", "upload"))
    )
        header("Content-Type: text/plain; charset={$this->charset}");

    $return = $this->$method();
    echo ($return === true)
        ? '{}'
        : $return;
}`

The problem is in the session, even being correct with the folder, the files are not loaded, and thus generates an error in js/50.init.js, because there is no return of the data in json.

Opening the core/class/browse.php file, init function, when I use _printr in the $data array, has data for files and folders, but it`s not passed to javascript to view the files, causing unknow error in 50.init.js.

If you do not have this year / month setting everything works ok. If I click on any folder, it also works ok.

Any idea what I can do to solve it?

iamShahMasum commented 4 years ago

function makeDir(){ date_default_timezone_set('Asia/Kolkata'); $year = date("Y"); $month = date("m"); $day = date("d"); $directory = "$year/$month/$day/"; if(!is_dir($directory)){ mkdir($directory, 755, true); } return $directory; }

return array(

// GENERAL SETTINGS

'disabled' => false,
'uploadURL' => makeDir(),
'uploadDir' => "",
'theme' => "default",

'types' => array(

// (F)CKEditor types
    'files'   =>  "",
    'flash'   =>  "swf",
    'images'  =>  "*img",

// TinyMCE types
    'file'    =>  "",
    'media'   =>  "swf flv avi mpg mpeg qt mov wmv asf rm",
    'image'   =>  "*img",
),

// IMAGE SETTINGS

'imageDriversPriority' => "imagick gmagick gd",
'jpegQuality' => 90,
'thumbsDir' => ".thumbs",

'maxImageWidth' => 0,
'maxImageHeight' => 0,

'thumbWidth' => 100,
'thumbHeight' => 100,

'watermark' => "The Janambhumi",

// DISABLE / ENABLE SETTINGS

'denyZipDownload' => false,
'denyUpdateCheck' => false,
'denyExtensionRename' => false,

// PERMISSION SETTINGS

'dirPerms' => 0755,
'filePerms' => 0644,

'access' => array(

    'files' => array(
        'upload' => true,
        'delete' => true,
        'copy'   => true,
        'move'   => true,
        'rename' => true
    ),

    'dirs' => array(
        'create' => true,
        'delete' => true,
        'rename' => true
    )
),

'deniedExts' => "exe com msi bat cgi pl php phps phtml php3 php4 php5 php6 py pyc pyo pcgi pcgi3 pcgi4 pcgi5 pchi6",

// MISC SETTINGS

'filenameChangeChars' => array(/*
    ' ' => "_",
    ':' => "."
*/),

'dirnameChangeChars' => array(/*
    ' ' => "_",
    ':' => "."
*/),

'mime_magic' => "",

'cookieDomain' => "",
'cookiePath' => "",
'cookiePrefix' => 'KCFINDER_',

// THE FOLLOWING SETTINGS CANNOT BE OVERRIDED WITH SESSION SETTINGS

'_sessionVar' => "KCFINDER",
'_check4htaccess' => true,
'_normalizeFilenames' => false,
'_dropUploadMaxFilesize' => 10485760,
//'_tinyMCEPath' => "/tiny_mce",
//'_cssMinCmd' => "java -jar /path/to/yuicompressor.jar --type css {file}",
//'_jsMinCmd' => "java -jar /path/to/yuicompressor.jar --type js {file}",

);