Exemplo n.º 1
0
 /**
  * 
  * @return \Zend\Http\PhpEnvironment\Request
  */
 function createRefererRequest($expectedUrl)
 {
     $headers = new \Zend\Http\Headers();
     $headers->addHeaderLine('Referer', $expectedUrl);
     $request = new \Zend\Http\PhpEnvironment\Request();
     $request->setHeaders($headers);
     return $request;
 }
 /**
  * @see \Doctrine\DBAL\Types\JsonArrayType::convertToPHPValue()
  * @param string $sValue
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $oPlatform
  * @throws \Doctrine\DBAL\Types\ConversionException
  * @return \Zend\Http\Headers
  */
 public function convertToPHPValue($sValue, \Doctrine\DBAL\Platforms\AbstractPlatform $oPlatform)
 {
     $aValue = parent::convertToPHPValue($sValue, $oPlatform);
     if (is_array($aValue)) {
         $oHeaders = new \Zend\Http\Headers();
         return $oHeaders->addHeaders($aValue);
     }
     throw \Doctrine\DBAL\Types\ConversionException::conversionFailedFormat($sValue, $this->getName(), 'json encoded array');
 }
Exemplo n.º 3
0
 public function enquireAction()
 {
     $serviceManager = $this->getServiceLocator();
     $this->enquiryTable = $serviceManager->get('Productsite\\Model\\EnquiryTable');
     $this->enquiryTable->createEnquiry($this->getRequest()->getPost()->toArray());
     $response = $this->getResponse();
     $response->setStatusCode("302");
     $headers = new \Zend\Http\Headers();
     $location = new \Zend\Http\Header\Location();
     $location->setUri('/productsite/catalog/index');
     $headers->addHeader($location);
     $response->setHeaders($headers);
     return $response;
 }
 public function __invoke($filePath)
 {
     // file path should be full
     // /var/www/html/zf2_project_name/public/file.txt
     if (file_exists($filePath)) {
         $response = new \Zend\Http\Response\Stream();
         $response->setStream(fopen($filePath, 'r'));
         $response->setStatusCode(200);
         $response->setStreamName(basename($filePath));
         $headers = new \Zend\Http\Headers();
         $headers->addHeaders(array('Content-Disposition' => 'attachment; filename="' . basename($filePath) . '"', 'Content-Type' => 'application/octet-stream', 'Content-Length' => filesize($filePath), 'Expires' => '@0', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'public'));
         $response->setHeaders($headers);
         return $response;
     } else {
         die('File not exist');
     }
 }
Exemplo n.º 5
0
 public function enquireAction()
 {
     $request = $this->getRequest();
     $serviceManager = $this->getServiceLocator();
     $this->chaseTable = $serviceManager->get('Productsite\\Model\\ChaseTable');
     $this->chaseTable->createChase($request->getPost()->toArray());
     if ($request->isXmlHttpRequest()) {
         $response = $this->getResponse();
         $response->setStatusCode(200);
         $response->setContent(\json_encode(array('success' => TRUE)));
         return $response;
     } else {
         $response = $this->getResponse();
         $response->setStatusCode("302");
         $headers = new \Zend\Http\Headers();
         $location = new \Zend\Http\Header\Location();
         $location->setUri('/');
         $headers->addHeader($location);
         $response->setHeaders($headers);
         return $response;
     }
 }
 public function downloadAction()
 {
     $file = getcwd() . '/module/media/src/media/upload/' . $this->params('file');
     $response = new \Zend\Http\Response\Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStatusCode(200);
     $response->setStreamName(basename($file));
     $headers = new \Zend\Http\Headers();
     $headers->addHeaders(array('Content-Disposition' => 'attachment; filename="' . basename($file) . '"', 'Content-Type' => 'application/octet-stream', 'Content-Length' => filesize($file), 'Expires' => '@0', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'public'));
     $response->setHeaders($headers);
     return $response;
 }
 public function downloadfileAction()
 {
     $this->checkAuth();
     $id = $this->params()->fromQuery('id', 0);
     $attachment = $this->databaseService->getFileAttachment($id);
     $file = '.' . Config::FILE_ATTACHMENT_PATH . $attachment->task_id . '/' . $attachment->real_name;
     $response = new \Zend\Http\Response\Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStatusCode(200);
     $response->setStreamName(basename($file));
     $headers = new \Zend\Http\Headers();
     $headers->addHeaders(array('Content-Disposition' => 'attachment; filename="' . basename($attachment->file_name) . '"', 'Content-Type' => 'application/octet-stream', 'Content-Length' => filesize($file), 'Expires' => '@0', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'public'));
     $response->setHeaders($headers);
     return $response;
 }
Exemplo n.º 8
0
 /**
  * Returns a response suitable for offering a file download.
  * In most modern browsers this function will cause the browser to display
  * the file and give the user the option to save it.
  *
  * @param string $path The CFS path of the file to download
  * @param string $fileName The file name to give the downloaded file
  *
  * @return \Zend\Http\Response\|null If the given file is not found, null is returned
  */
 public function downloadFile($path, $fileName)
 {
     $config = $this->getConfig();
     $file = $config['storage_dir'] . '/' . $path;
     if (!file_exists($file)) {
         return null;
     }
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $type = finfo_file($finfo, $file);
     finfo_close($finfo);
     $response = new \Zend\Http\Response\Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStatusCode(200);
     $response->setStreamName($fileName);
     $headers = new \Zend\Http\Headers();
     $headers->addHeaders(['Content-Disposition' => 'inline; filename="' . $fileName . '"', 'Content-Type' => $type, 'Content-Length' => filesize($file), 'Expires' => '+1 year', 'Cache-Control' => 'public', 'Pragma' => '']);
     $response->setHeaders($headers);
     return $response;
 }
Exemplo n.º 9
0
 public function __invoke($file, $sourceName = null)
 {
     $response = new \Zend\Http\Response\Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStatusCode(200);
     $response->setStreamName(basename($file));
     $headers = new \Zend\Http\Headers();
     if (!$sourceName) {
         $sourceName = basename($file);
     }
     $file_extension = strtolower(substr(strrchr($file, "."), 1));
     switch ($file_extension) {
         case "pdf":
             $ctype = "application/pdf";
             break;
         case "exe":
             $ctype = "application/octet-stream";
             break;
         case "zip":
             $ctype = "application/zip";
             break;
         case "odt":
             $ctype = "application/vnd.oasis.opendocument.text";
             break;
         case "doc":
             $ctype = "application/msword";
             break;
         case "docx":
             $ctype = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
             break;
         case "dotx":
             $ctype = "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
             break;
         case "ods":
             $ctype = "application/vnd.oasis.opendocument.spreadsheet";
             break;
         case "xls":
             $ctype = "application/vnd.ms-excel";
             break;
         case "xlsx":
             $ctype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
             break;
         case "xltx":
             $ctype = "application/vnd.openxmlformats-officedocument.spreadsheetml.template";
             break;
         case "xlam":
             $ctype = "application/vnd.ms-excel.addin.macroEnabled.12";
             break;
         case "xlsb":
             $ctype = "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
             break;
         case "odp":
             $ctype = "application/vnd.oasis.opendocument.presentation";
             break;
         case "ppt":
             $ctype = "application/vnd.ms-powerpoint";
             break;
         case "potx":
             $ctype = "application/vnd.openxmlformats-officedocument.presentationml.template";
             break;
         case "ppsx":
             $ctype = "application/vnd.openxmlformats-officedocument.presentationml.slideshow";
             break;
         case "pptx":
             $ctype = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
             break;
         case "sldx":
             $ctype = "application/vnd.openxmlformats-officedocument.presentationml.slide";
             break;
         case "gif":
             $ctype = "image/gif";
             break;
         case "png":
             $ctype = "image/png";
             break;
         case "mp3":
             $ctype = "audio/mpeg3";
             break;
         case "wav":
             $ctype = "audio/wav";
             break;
         case "mpeg":
         case "mpg":
             $ctype = "video/mpeg";
             break;
         case "avi":
             $ctype = "video/avi";
             break;
         case "jpeg":
         case "jpg":
             $ctype = "image/jpg";
             break;
         default:
             $ctype = "application/force-download";
     }
     $headers->addHeaders(array('Content-Disposition' => 'attachment; filename="' . $sourceName . '"', 'Content-Type' => $ctype, 'Content-Length' => filesize($file), 'Expires' => '@0', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'public'));
     $response->setHeaders($headers);
     return $response;
 }
Exemplo n.º 10
0
 public function downloadFile($filename, $ispublic = false, $userdir = null)
 {
     $destenation = $this->checkDestenation($filename, $ispublic);
     if (!$destenation) {
         return false;
     }
     $response = new \Zend\Http\Response\Stream();
     $headers = new \Zend\Http\Headers();
     $headers->addHeaderLine('Content-Type', 'application/octet-stream')->addHeaderLine('Content-Disposition', 'attachment; filename="' . $filename . '"')->addHeaderLine('Content-Length', filesize($destenation));
     $response->setHeaders($headers);
     $response->setStream($stream = fopen($destenation, 'r'));
     $response->setStatusCode(200);
     return $response;
 }
Exemplo n.º 11
0
 /**
  * Returns a zend response to be used for downloading a photo.
  *
  * @param integer $photoId
  * @return \Zend\Http\Response\Stream
  */
 public function getPhotoDownload($photoId)
 {
     if (!$this->isAllowed('download')) {
         throw new \User\Permissions\NotAllowedException($this->getTranslator()->translate('Not allowed to download photos'));
     }
     $photo = $this->getPhoto($photoId);
     $config = $this->getConfig();
     $file = $config['upload_dir'] . '/' . $photo->getPath();
     $fileName = $this->getPhotoFileName($photo);
     //TODO: ACL
     $response = new \Zend\Http\Response\Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStatusCode(200);
     $response->setStreamName($fileName);
     $headers = new \Zend\Http\Headers();
     $headers->addHeaders(array('Content-Disposition' => 'attachment; filename="' . $fileName . '"', 'Content-Type' => 'application/octet-stream', 'Content-Length' => filesize($file), 'Expires' => '@0', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'public'));
     $response->setHeaders($headers);
     return $response;
 }
 /**
  * Загрузка файла
  * @return \Zend\Http\Response\Stream
  */
 public function downloadAction()
 {
     if ($this->request->isGet()) {
         $fileId = $this->params("id");
         $uploadTable = $this->getServiceLocator()->get('UploadTable');
         $upload = $uploadTable->getById($fileId);
         $fileName = $upload->getFileName();
         $fileInitialName = $upload->getFileName();
         $fileNameP = $this->getFileUploadLocation() . DIRECTORY_SEPARATOR . $fileName;
         $response = new \Zend\Http\Response\Stream();
         $response->setStream(fopen($fileNameP, 'r'));
         $response->setStatusCode(200);
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $headers = new \Zend\Http\Headers();
         $headers->addHeaderLine('Content-Type', finfo_file($finfo, $fileNameP))->addHeaderLine('Content-Disposition', 'attachment; filename="' . $fileInitialName . '"')->addHeaderLine('Content-Length', filesize($fileNameP));
         $response->setHeaders($headers);
         return $response;
     }
 }
Exemplo n.º 13
0
 public function downloadEticketAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('admin/order', array());
     }
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $package = $em->getRepository("ErsBase\\Entity\\Package")->findOneBy(array('id' => $id));
     /*$languages = array(
           array(
               'label' => 'English',
               'value' => 'en',
           ),
           array(
               'label' => 'German',
               'value' => 'de',
           ),
           array(
               'label' => 'Italian',
               'value' => 'it',
           ),
           array(
               'label' => 'Spanish',
               'value' => 'es',
           ),
           array(
               'label' => 'French',
               'value' => 'fr',
           ),
       );*/
     $form = new Form\DownloadEticket();
     /*$form->get('language')->setValueOptions($languages);*/
     $form->get('submit')->setValue('Download');
     $form->get('id')->setValue($package->getId());
     $forrest = new Service\BreadcrumbService();
     if (!$forrest->exists('package')) {
         $forrest->set('package', 'admin/order');
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         #$form->setInputFilter($agegroup->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $id = (int) $request->getPost('id');
             $package = $em->getRepository("ErsBase\\Entity\\Package")->findOneBy(array('id' => $id));
             $eticketService = $this->getServiceLocator()->get('ErsBase\\Service\\ETicketService');
             #$eticketService->setLanguage($request->getPost('language'));
             $eticketService->setPackage($package);
             $file = $eticketService->generatePdf();
             $response = new \Zend\Http\Response\Stream();
             $response->setStream(fopen($file, 'r'));
             $response->setStatusCode(200);
             $response->setStreamName(basename($file));
             $headers = new \Zend\Http\Headers();
             $headers->addHeaders(array('Content-Disposition' => 'attachment; filename="' . basename($file) . '"', 'Content-Type' => 'application/octet-stream', 'Content-Length' => filesize($file), 'Expires' => '@0', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'public'));
             $response->setHeaders($headers);
             return $response;
         } else {
             $logger = $this->getServiceLocator()->get('Logger');
             $logger->warn($form->getMessages());
         }
     }
     return new ViewModel(array('form' => $form, 'package' => $package, 'breadcrumb' => $forrest->get('package')));
 }
Exemplo n.º 14
0
 public function downloadFileAction()
 {
     $fileName = urldecode($this->params()->fromRoute("fileName", null));
     echo ROOT_PATH . '/' . $fileName;
     var_dump(file_exists(ROOT_PATH . '/' . $fileName));
     if (!$fileName || !file_exists(ROOT_PATH . '/' . $fileName)) {
         return $this->notFoundAction();
     } else {
         $pathInfo = pathinfo($fileName);
         switch ($pathInfo['extension']) {
             case "pdf":
                 $type = "application/pdf";
                 break;
             case "xls":
                 $type = "application/vnd.ms-excel";
                 break;
             case "zip":
                 $type = "application/zip";
                 break;
             case "ppt":
                 $type = "application/vnd.ms-powerpoint";
                 break;
             default:
                 $type = "text/plain";
         }
         $response = new Stream();
         $response->setStream(fopen($fileName, 'r'));
         $response->setStatusCode(200);
         $headers = new \Zend\Http\Headers();
         $headers->addHeaderLine('Content-Type', $type)->addHeaderLine('Content-Disposition', 'attachment; filename="' . $fileName . '"')->addHeaderLine('Content-Length', filesize($fileName));
         $response->setHeaders($headers);
         return $response;
     }
 }
Exemplo n.º 15
0
 public function loadattach()
 {
     //error_reporting(E_ALL);
     //ini_set('display_errors',1);
     $request = $this->getMvcEvent()->getRequest();
     $stream = new \Zend\Http\Response\Stream();
     $file = $request->getQuery("file");
     $path = $this->getPathFileUpload();
     if ($file == '') {
         throw new \Exception('Allegato non specificato');
     }
     $fileDetail = explode(self::paramsSeparator, $file);
     $mimeType = $this->validateMimeType($fileDetail[0]);
     $stream->setStream(fopen($path . DIRECTORY_SEPARATOR . $fileDetail[0], 'r'));
     $stream->setStatusCode(200);
     $headers = new \Zend\Http\Headers();
     $headers->addHeaderLine('Content-Type', $mimeType)->addHeaderLine('Content-Disposition', 'attachment;filename="' . $fileDetail[1] . '"')->addHeaderLine('Content-Length', filesize($path . DIRECTORY_SEPARATOR . $fileDetail[0]));
     ob_end_clean();
     $stream->setHeaders($headers);
     return $stream;
 }
Exemplo n.º 16
0
 public function getPDFResponse($template, $variables = [], $params = [])
 {
     $markup = $this->getPDFMarkup($template, $variables, $params);
     $response = new \Zend\Http\Response();
     $response->setContent($markup);
     $headers = new \Zend\Http\Headers();
     $filename = isset($params['fileName']) ? 'filename=' . $params['fileName'] . '.pdf' : 'filename=' . $this->defaultFileName;
     $headers->addHeaders(['Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; ' . $filename . '', 'Content-Transfer-Encoding' => 'binary', 'Content-Length' => strlen($markup), 'Accept-Ranges' => 'bytes']);
     $response->setHeaders($headers);
     return $response;
 }
 public function downloadFile($destenation, $filename, $ispublic = false)
 {
     if (!$this->has($destenation)) {
         return false;
     }
     $content = $this->read($destenation);
     $response = new \Zend\Http\Response\Stream();
     $headers = new \Zend\Http\Headers();
     $headers->addHeaderLine('Content-Type', 'application/octet-stream')->addHeaderLine('Content-Disposition', 'attachment; filename="' . $filename . '"')->addHeaderLine('Content-Length', strlen($content));
     $response->setHeaders($headers);
     $response->setStream(fopen('data://text/plain;base64,' . base64_encode($content), 'r'));
     $response->setStatusCode(200);
     return $response;
 }