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

imagejpeg(/1/4/original.jpg): failed to open stream: Is a directory #63

Open
amismailz opened this issue Nov 18, 2018 · 4 comments
Open

Comments

@amismailz
Copy link

amismailz commented Nov 18, 2018

I am facing a strange behaviour of the extension! original.jpg is being created as a directory and I got the error below when trying to upload

screenshot from 2018-11-18 11-01-47

@davarresc
Copy link
Contributor

davarresc commented Nov 18, 2018

The GalleryBehavior class has been refactorized and createFolders method has a bug. Due to the normalizePath method, the createDirectory method understands the file name as a folder and create the folders with the 'file/to/path/image.jpg' path instead of 'file/to/path'.

If you override createFolders method from GalleryBehavior class, it works fine. For example:

class GalleryBehavior extends \zxbodya\yii2\galleryManager\GalleryBehavior
{

    private function createFolders($filePath)
    {
        return FileHelper::createDirectory(FileHelper::normalizePath(dirname($filePath)), 0777);
    }

    /**
     * Replace existing image by specified file
     *
     * @param $imageId
     * @param $path
     */
    public function replaceImage($imageId, $path)
    {
        $this->createFolders($this->getFilePath($imageId, 'original'));

        $originalImage = Image::getImagine()->open($path);
        //save image in original size

        //create image preview for gallery manager
        foreach ($this->versions as $version => $fn) {
            /** @var ImageInterface $image */

            $image = call_user_func($fn, $originalImage);
            if (is_array($image)) {
                list($image, $options) = $image;
            } else {
                $options = [];
            }

            $image
                ->save($this->getFilePath($imageId, $version), $options);
        }
    }
}

@zxbodya
Copy link
Owner

zxbodya commented Nov 18, 2018

Hi,
@davarresc thanks for checking this - indeed there was PR merged recently, changing this method #62

can you create pr with your fix?

@davarresc
Copy link
Contributor

Hi,
Yes of course, I just did the PR.
Regards.

@zxbodya
Copy link
Owner

zxbodya commented Nov 18, 2018

thanks, merged it 👍
@amismailz can you check is it fixed you issue?

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

3 participants