Skip to content

Commit

Permalink
FileResponse: added some checks (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
tacoberu authored and dg committed Jan 5, 2020
1 parent 72ea54a commit fa35b41
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Application/Responses/FileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ final class FileResponse implements Nette\Application\IResponse

public function __construct(string $file, string $name = null, string $contentType = null, bool $forceDownload = true)
{
if (!is_file($file)) {
throw new Nette\Application\BadRequestException("File '$file' doesn't exist.");
if (!is_file($file) || !is_readable($file)) {
throw new Nette\Application\BadRequestException("File '$file' doesn't exist or is not readable.");
}

$this->file = $file;
Expand Down Expand Up @@ -88,6 +88,9 @@ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $htt

$filesize = $length = filesize($this->file);
$handle = fopen($this->file, 'r');
if (!$handle) {
throw new Nette\Application\BadRequestException("Cannot open file: '{$this->file}'.");
}

if ($this->resuming) {
$httpResponse->setHeader('Accept-Ranges', 'bytes');
Expand Down

0 comments on commit fa35b41

Please sign in to comment.