barryvdh / laravel-elfinder

elFinder bundle for Laravel
745 stars 171 forks source link

add Custom Driver #215

Open webineh opened 6 years ago

webineh commented 6 years ago

i have Custom driver this save tmb in same name and same directory original size

when i define it in Config/elfinder.php it work fine but have error in php artisan route:cache or php artisan config:cache

what is best way override class in elfinder laravel ???

class elFinderVolumeCustomLocalFileSystem extends elFinderVolumeLocalFileSystem
{

    protected function tmbname($stat) {
        $dir = $this->relpathCE($this->decode($stat['phash']));
        if (!is_dir($this->tmbPath.DIRECTORY_SEPARATOR.$dir)) {
            $dirs = explode(DIRECTORY_SEPARATOR, $dir);
            $target = $this->tmbPath;
            foreach($dirs as $_dir) {
                if (! is_dir($target . DIRECTORY_SEPARATOR . $_dir)) {
                    mkdir($target . DIRECTORY_SEPARATOR . $_dir);
                }
                $target = $target . DIRECTORY_SEPARATOR . $_dir;
            }
        }
        return $dir . DIRECTORY_SEPARATOR . $stat['name']  ;
    }

    protected function gettmb($path, $stat) {
        if ($name = parent::gettmb($path, $stat)) {
            $name = str_replace('\\', '/', $name); // For windows server
            $name = str_replace('%2F', '/', rawurlencode($name));
        }
        return $name;
    }

    public function tmb($hash) {
        if ($name = parent::tmb($hash)) {
            $name = str_replace('\\', '/', $name); // For windows server
            $name = str_replace('%2F', '/', rawurlencode($name));
        }
        return $name;
    }

}