Example #1
0
 /**
  * Action - image
  * display images in the predetermined size or in the natural size
  *
  * Access to the action is possible in the following paths:
  * - /utility/image
  *
  * @return void
  */
 public function imageAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $username = $request->getQuery('username');
     $id = (int) $request->getQuery('id');
     $w = (int) $request->getQuery('w');
     $h = (int) $request->getQuery('h');
     $hash = $request->getQuery('hash');
     $realHash = Default_Model_DbTable_BlogPostImage::GetImageHash($id, $w, $h);
     // disable autorendering since we're outputting an image
     $this->_helper->viewRenderer->setNoRender();
     $image = new Default_Model_DbTable_BlogPostImage($this->db);
     if ($hash != $realHash || !$image->load($id)) {
         // image not found
         $response->setHttpResponseCode(404);
         return;
     }
     try {
         $fullpath = $image->createThumbnail($w, $h, $username);
     } catch (Exception $ex) {
         $fullpath = $image->getFullPath($username);
     }
     $info = getImageSize($fullpath);
     $response->setHeader('content-type', $info['mime']);
     $response->setHeader('content-length', filesize($fullpath));
     echo file_get_contents($fullpath);
 }