Assuming you have a route as following:

`/thumbs/:x-:y-:name.png`

and this route leads to a controller like following (pseudo-code):

class MyController extends AbstractActionController {
    public function indexAction() {
        if (!file_exists($name)) { // lots of validation rules here! You're
exposing your filesystem
            return $this->notFoundAction();
        }

        $thumb = generate_thumb($name, $x, $y);
        save_thumb("public/thumbs/$x-$y-$name.png");
        $response->setBody(/* image content */); // also set headers!
    }
}

That will hit PHP only once when requesting`/thumbs/100-200-blah.png`

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 8 February 2013 22:22, Ralf Eggert <[email protected]> wrote:

> Hi,
>
> My application is mainly just delivering images. Each image exists for a
> minimum size of 800x600 pixel on disk. When a thumbnail is requested for
> the first time, this file does not exist. So my action controller should
> check if the current url is a request for a thumbnail version of an
> image. It should generate the thumbnail, save and deliver it. All
> subsequent calls for this file should just deliver the image from disk.
> If a request is not for a thumbnail version (a real 404) then the normal
> 404 page should be delivered and the 404 status code should be sent.
>
> What is the best approach for this scenario?
>
> Regards,
>
> Ralf
>
> --
> List: [email protected]
> Info: http://framework.zend.com/archives
> Unsubscribe: [email protected]
>
>
>

Reply via email to