Hello,

I am trying to create an Image-proxy which caches image-urls on disk and outputs these jpegs to the browser. The following code wont work. On the first Cache Miss, the image is properly shown. On each following Cache Hit, the image is not displayed (invalid data). The cache file on disk contains the proper jpeg-image, at least irfanview recognizes it being jpeg...
Any hint? Thanks!
Kai

$frontend = 'Output';
$frontendOpts = array(
    'caching' => true,
    'cache_id_prefix' => 'ImageServiceProxy_',
    'lifetime' => NULL,
    'ignore_user_abort' => true
);

$backend  = 'File';
$backendOpts = array(
    'cache_dir' => CACHEDIR,
    'read_control' => false,
    'hashed_directory_level' => 3,
);

$cache = Zend_Cache::factory($frontend, $backend, $frontendOpts, $backendOpts);

header('Content-Type: image/jpeg');

if (!$cache->load($cacheID)) {

    $http = new Zend_Http_Client($url);
    $http->setHeaders('User-Agent', $_SERVER['HTTP_USER_AGENT']);
$http->setHeaders('Referer', 'http://' . $http->getUri()->getHost() . '/');
    $res = $http->request('GET');
    $img = $res->getRawBody();

    imagejpeg(imagecreatefromstring($img));

    $cache->end();
}
exit;



Reply via email to