Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否升级下支持 Laravel 9.X #41

Open
imnpc opened this issue Mar 14, 2022 · 1 comment
Open

能否升级下支持 Laravel 9.X #41

imnpc opened this issue Mar 14, 2022 · 1 comment

Comments

@imnpc
Copy link

imnpc commented Mar 14, 2022

目前只能支持到 Laravel 8.X

@crmzhangwei
Copy link

crmzhangwei commented Jul 12, 2024

vendor\overtrue\laravel-ueditor\src\StorageManager.php 代码路径

改下代码可以支持
protected function getUploadConfig($action)
{
$upload = config('ueditor.upload');

    $prefixes = [
        'image', 'scrawl', 'snapscreen', 'catcher', 'video', 'file',
        'imageManager', 'fileManager',
    ];

    $config = [];

    foreach ($prefixes as $prefix) {
        if ($action == $upload[$prefix.'ActionName']) {
            $config = [
                'action' => self::array_get($upload, $prefix.'ActionName'),
                'field_name' => self::array_get($upload, $prefix.'FieldName'),
                'max_size' => self::array_get($upload, $prefix.'MaxSize'),
                'allow_files' => self::array_get($upload, $prefix.'AllowFiles', []),
                'path_format' => self::array_get($upload, $prefix.'PathFormat'),
            ];

            break;
        }
    }

    return $config;
}
static function array_get($array, $key, $default = null)
{
    if (is_null($key)) {
        return $array; 
    }

    if (isset($array[$key])) {
        return $array[$key];
    }

    foreach (explode('.', $key) as $segment) {
        if (! is_array($array) || ! array_key_exists($segment, $array)) {
            return value($default);
        }

        $array = $array[$segment];
    }
    return $array;
}

/**
* Format the storage path.
*
* @param string $path
* @param string $filename
*
* @return mixed
*/
protected function formatPath($path, $filename)
{
$replacement = array_merge(explode('-', date('Y-y-m-d-H-i-s')), [$filename, time()]);
$placeholders = ['{yyyy}', '{yy}', '{mm}', '{dd}', '{hh}', '{ii}', '{ss}', '{filename}', '{time}'];
$path = str_replace($placeholders, $replacement, $path);

    //替换随机字符串
    if (preg_match('/\{rand\:([\d]*)\}/i', $path, $matches)) {
        $length = min($matches[1], strlen(PHP_INT_MAX));
        $path = preg_replace('/\{rand\:[\d]*\}/i', str_pad(mt_rand(0, pow(10, $length) - 1), $length, '0', STR_PAD_LEFT), $path);
    }

    if (!str_contains($path, $filename)) {
      
        $path = Str::endsWith($path, '/') ? $path : $path."/";  
        $path.=$filename;
    }

    return $path;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants