Exemple #1
0
 /**
  * @return string
  */
 public function render()
 {
     # As of this writing, Json header is not automatically sent in the BE... even with json=format.
     $this->response->setHeader('Content-Type', 'application/json');
     $this->response->sendHeaders();
     return json_encode($this->result->toArray());
 }
 /**
  * @param \I4W\Fileshare\Domain\Model\Share $share
  * @throws \RuntimeException
  * @throws \TYPO3\CMS\Core\Error\Http\PageNotFoundException
  * @return string
  * @dontvalidate
  */
 public function downloadAllAction(\I4W\Fileshare\Domain\Model\Share $share = null)
 {
     if (false === $share instanceof Share) {
         throw new PageNotFoundException('Could not find  share', 1435910678);
     }
     $zip = new \ZipArchive();
     $res = $zip->open($share->getToken() . '.zip', \ZipArchive::CREATE);
     if (!$res) {
         throw new \RuntimeException('Could not create ZIP archive', 1435909664);
     }
     foreach ($this->getFilesFromShare($share) as $file) {
         /** @var File $file */
         $zip->addFromString($file->getName(), $file->getContents());
     }
     $zip->close();
     $this->response->setHeader('Cache-control', 'public', true);
     $this->response->setHeader('Content-Description', 'File transfer', true);
     $this->response->setHeader('Content-Disposition', 'attachment; filename=' . $share->getToken() . '.zip', true);
     $this->response->setHeader('Content-Type', 'application/zip', true);
     $this->response->sendHeaders();
     readfile($share->getToken() . '.zip');
     exit;
 }