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

ImagePreviewer on Windows #12

Open
juppwerner opened this issue Jan 20, 2022 · 1 comment
Open

ImagePreviewer on Windows #12

juppwerner opened this issue Jan 20, 2022 · 1 comment

Comments

@juppwerner
Copy link

Hi,
thanks for this great Yii2 extension!

I am testing this on my Windows dev PC.
The preview for image files in the form view does not work.

Here is my fix to the function prepareFolder in the file sc/logic/ImagePreviewer.php:

protected function prepareFolder()
{
    // Windows: remove a double backslash:
    $this->fileName = str_replace("\\\\", "\\", $this->fileName);
    // Windows: convert backslash to forward slash, works too:
    $this->fileName = str_replace("\\", "/", $this->fileName);
    if (!file_exists(Yii::$app->getModule('files')->cacheFullPath))
        mkdir(Yii::$app->getModule('files')->cacheFullPath);
    $lastFolder = '/';
    // Windows: don't start with slash, first part is drive letter w/o slash
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
        $lastFolder = '';
    $explodes = explode('/', $this->fileName);
    array_pop($explodes);
    if (empty($explodes))
        return;
    foreach ($explodes as $folder) {
        if (empty($folder))
            continue;
        $lastFolder = $lastFolder . $folder . '/';
        if (!file_exists($lastFolder))
            mkdir($lastFolder);
    }
}

Thanks for adding this.

Regards
Joachim

@floor12
Copy link
Owner

floor12 commented Jan 21, 2022

Hello!
Thank you.

I can not say anything about the work of my module on the window. PHP applications in production are always run on Unix machines, and therefore they must be developed in a similar environment. I always use docker for development, and forgot about these problems forever. I highly recommend using it too

If you want to make changes to the code, make a pull request and if everything works, I will update the library. No problem at all.

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