Commit f13bb56e by Dirk Benkert

fixed memory exhaustion on file download because of output buffering

parent 18746d0d
<?php
/**
* Dirk Benkert (https://www.dirk-benkert.de/)
*
......@@ -20,7 +21,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Description for UserController
*
......@@ -76,7 +76,7 @@ class FilesController extends ControllerAbstract {
PaginationFilterSort::ENTITY => 'Application\Entity\File',
));
return $plugin->getViewModel(array(
'folder_id' => $this->getRequest()->getQuery('folder_id', false)
'folder_id' => $this->getRequest()->getQuery('folder_id', false)
));
}
......@@ -135,13 +135,22 @@ class FilesController extends ControllerAbstract {
$response = new \Zend\Http\Response\Stream();
$response->setStream(fopen($file->path, 'r'));
$response->setStatusCode(200);
$response->setStreamName($file->name);
$headers = new \Zend\Http\Headers();
$headers->addHeaderLine('Content-Type', $file->type)
->addHeaderLine('Content-Disposition', 'attachment; filename="' . $file->name . '"')
$headers->addHeaderLine('Content-Disposition', 'attachment; filename="' . $file->name . '"')
->addHeaderLine('Content-Type', $file->type)
->addHeaderLine('Content-Length', $file->size);
$response->setHeaders($headers);
// disable output buffering to prevent memory exhaustion on sending larger files
$level = ob_get_level();
while ($level > 0) {
ob_end_clean();
$level--;
}
return $response;
} else {
throw new FileNotFoundException(sprintf('"%s" not found', $filepath));
......@@ -183,7 +192,8 @@ class FilesController extends ControllerAbstract {
),
Crud::EDIT_TEMPLATE => 'application/files/edit.phtml',
Crud::MESSAGES => $this->message,
Crud::REPLACEMENTS => array('name'),
Crud::REPLACEMENTS => array('name'),
);
}
}
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 sign in to comment