500 internal server error - IOException: Failed to create media/cache/my_thumb with LiipImagineBundle

StackOverflow https://stackoverflow.com/questions/22558068

I am trying to apply a filter on an image based on LiipImagineBundle.

Here are the steps:

  1. Installation through the composer file by adding this line:

    "liip/imagine-bundle": "1.0.*@dev"

  2. Configuration of the config.yml file by adding these lines:

    liip_imagine:
        resolvers:
        default:
            web_path:  
                web_root: %kernel.root_dir%/../web
                cache_prefix: media/cache
    
    filter_sets:
        cache: ~
        my_thumb:
            quality: 75
            filters:
              thumbnail: { size: [120, 90], mode: outbound }
    
  3. Declaration of the bundle in AppKernel.php:

    new Liip\ImagineBundle\LiipImagineBundle(),
    
  4. Testing the bundle by adding there line the twig file:

    <img src="{{ asset('img/test.jpg') | imagine_filter('my_thumb') }}" />
    

But, no image was displayed. The generated HTML file contains:

<img src="http://localhost/tuto/web/app_dev.php/media/cache/my_thumb/img/test.jpg">

And in the javascript console of the browser, I find this error:

GET http://localhost/tuto/web/app_dev.php/media/cache/my_thumb/img/test.jpg 500 (Internal Server Error)

When I try to open the link (with the 500 Internal Server Error), symfony throws this error:

Failed to create /home/amine/NetBeansProjects/tuto/app/../web/media/cache/my_thumb/img 500 Internal Server Error - IOException

I guess I do not have the permission to create the following folder: /home/amine/NetBeansProjects/tuto/app/../web/media/cache/my_thumb/img. In my point of view, it was expectable since I working on Ubuntu.

To avoid this problem, I directly changed the permissions on the folder web through sudo chmod 777 -R web but the problem is still the same.

Is there any idea?

有帮助吗?

解决方案 2

I thought it is working but it is not! It was loading image from old cache. Forget my last post!

I think there is a bug in the bundle. I explain:

Here is my new config of the bundle:

    liip_imagine:
        resolvers:
        default:
            web_path:  
                web_root: %kernel.root_dir%/../web/img
                # %kernel.root_dir%/../web/img is the folder where filtered images will be created!
                cache_prefix: media/cache
                # media/cache the prefix of folder where the cached images will be created

    filter_sets:
        cache: ~
        my_thumb:
            quality: 75
            filters:
              thumbnail: { size: [120, 90], mode: outbound }

This is the twig part for displaying the image:

{# This way the filtered image will not be created!#}
<img src="{{ 'img/test.jpg' | imagine_filter('my_thumb') }}" />

{# That way, the filted images will be created. asset() must be used. #}
<img src="{{ asset('img/test.jpg' | imagine_filter('my_thumb')) }}" />

The generated link of the image is not correct! In fact, the obtained link is:

http://localhost/media/cache/my_thumb/img/test.jpg

The expected correct link is:

http://localhost/**tuto/web/img**/media/cache/my_thumb/img/test.jpg

There is a missing part in the tuto/web/img . Is this a bug?

To avoid that problem, I did this:

<img src="{{ asset('img/test.jpg' | imagine_filter('my_thumb'))|replace({'media':'tuto/web/img/media'}) }}" />

I guess: playing with twig is not a good solution. I hope we will find a solution to this bug!

Thanks!

其他提示

The problem is almost solved. I changed the config.yml like this:

    liip_imagine:
        resolvers:
        default:
            web_path:  
                web_root: %kernel.root_dir%/../web/imagine
                # imagine is the folder where filtered images will be created!
                cache_prefix: tuto/web/imagine/media/cache
                # where tuto is the folder of my symfony application

    filter_sets:
        cache: ~
        my_thumb:
            quality: 75
            filters:
              thumbnail: { size: [120, 90], mode: outbound }

And for the twig part, it has been changed to:

<img src="{{ 'img/test.jpg' | imagine_filter('my_thumb') }}" />
{# where img is the folder where I put all my images!#}

My question is: is it possible to change the configuration of the parameter cache_prefix in a way I replace tuto by something else in order to have a configuration that works anywhere? I am asking this question because I would avoid problems when hosting the web site!

Thanks...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top