Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileResponse: added some checks #238

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Application/Responses/FileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function __construct(string $file, string $name = null, string $contentTy
if (!is_file($file)) {
throw new Nette\Application\BadRequestException("File '$file' doesn't exist.");
}
if (!is_readable($file)) {
throw new Nette\Application\BadRequestException("File '$file' is not readable.");
}

$this->file = $file;
$this->name = $name ?? basename($file);
Expand Down Expand Up @@ -88,6 +91,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}'.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot open file?


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