Exemple #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;
 }
 /**
  * Загрузка файла
  * @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 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;
     }
 }
 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;
 }
 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;
 }