Open amismailz opened 5 years ago
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);
}
}
}
Hi, @davarresc thanks for checking this - indeed there was PR merged recently, changing this method #62
can you create pr with your fix?
Hi, Yes of course, I just did the PR. Regards.
thanks, merged it 👍 @amismailz can you check is it fixed you issue?
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