Commit b3d576b6 authored by Tino Goratsch's avatar Tino Goratsch

deliver the to be downloaded file as a stream, so that we do not exceed the...

deliver the to be downloaded file as a stream, so that we do not exceed the PHP memory limit for bigger files...
parent 56e12ce3
......@@ -54,7 +54,7 @@ class BootstrapCache extends EventDispatchingHttpCache
{
$response = parent::handle($request, $type, $catch);
$this->moveStaticAssetsAround($response);
//$this->moveStaticAssetsAround($response);
return $response;
}
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Application\BootstrapCache;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class Esi extends \Symfony\Component\HttpKernel\HttpCache\Esi
{
/**
* @inheritdoc
*/
public function process(Request $request, Response $response)
{
if ($response instanceof BinaryFileResponse) {
return $response;
}
return parent::process($request, $response);
}
}
......@@ -8,6 +8,7 @@ namespace ACP3\Modules\ACP3\Files\Controller\Frontend\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Files;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
/**
......@@ -70,18 +71,13 @@ class Download extends Core\Controller\AbstractFrontendAction
$ext = strrchr($file['file'], '.');
$filename = $this->stringFormatter->makeStringUrlSafe($file['title']) . $ext;
$disposition = $this->response->headers->makeDisposition(
$response = new BinaryFileResponse($path . $file['file']);
$response->setContentDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$filename
);
$this->setContentType('application/force-download');
$this->response->headers->add([
'Content-Disposition' => $disposition,
'Content-Transfer-Encoding' => 'binary',
'Content-Length' => filesize($path . $file['file'])
]);
return $this->response->setContent(file_get_contents($path . $file['file']));
return $response;
} elseif (preg_match('/^([a-z]+):\/\//', $file['file'])) { // External file
return $this->redirect()->toNewPage($file['file']);
}
......
......@@ -34,7 +34,7 @@ $cacheStore = new \Symfony\Component\HttpKernel\HttpCache\Store(
$appCache = new \ACP3\Core\Application\BootstrapCache(
$kernel,
$cacheStore,
new \Symfony\Component\HttpKernel\HttpCache\Esi(),
new \ACP3\Core\Application\BootstrapCache\Esi(),
['debug' => $appMode === \ACP3\Core\Environment\ApplicationMode::DEVELOPMENT]
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment