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');
     }
 }
 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;
 }
Exemple #4
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;
 }
Exemple #5
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;
 }
Exemple #6
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;
     }
 }
 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;
 }
 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;
 }
Exemple #10
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')));
 }
 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;
 }