Example #1
0
 /**
  * Get the attachment on the wish
  *
  * @return  object WishlistModelAttachment
  */
 public function attachment()
 {
     if (!isset($this->_attachment)) {
         $this->_attachment = Attachment::getInstance(0, $this->get('id'));
     }
     return $this->_attachment;
 }
Example #2
0
 /**
  * Download an attachment
  *
  * @return     void
  */
 public function downloadTask()
 {
     $file = Request::getVar('file', '');
     $wishid = Request::getInt('wishid', 0);
     $wish = new Wish($wishid);
     // Ensure we have a path
     if (!$wish->exists() || $wish->isDeleted() || $wish->isWithdrawn()) {
         throw new Exception(Lang::txt('COM_WISHLIST_FILE_NOT_FOUND'), 404);
     }
     $attachment = new Attachment($file, $wishid);
     // Ensure we have a path
     if (!$attachment->exists()) {
         throw new Exception(Lang::txt('COM_WISHLIST_FILE_NOT_FOUND'), 404);
     }
     //make sure that file is acceptable type
     if (!$attachment->isAllowedType()) {
         throw new Exception(Lang::txt('Unknown file type.'), 404);
     }
     // Add PATH_CORE
     $filename = $attachment->link('file');
     // Ensure the file exist
     if (!file_exists($filename)) {
         throw new Exception(Lang::txt('COM_WISHLIST_FILE_NOT_FOUND') . ' ' . $filename, 404);
     }
     // Initiate a new content server and serve up the file
     $xserver = new Server();
     $xserver->filename($filename);
     $xserver->disposition('attachment');
     $xserver->acceptranges(false);
     // @TODO fix byte range support
     if (!$xserver->serve()) {
         // Should only get here on error
         throw new Exception(Lang::txt('COM_WISHLIST_SERVER_ERROR'), 500);
     } else {
         exit;
     }
     return;
 }