cakephp: Setting filename for inline attachment in response is missing

This is a (multiple allowed):

  • [] bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 4.1.2

What you did

In my response I want to send a file, but instead of forcing the download I want to set the Content-Disposition to “inline” so that the file (in this case a pdf) is opened in the browser and when the user decides to save the file, the specified filename should be used. This is not possible so far (or at least I did not find out how to do this).

A new method in Cake/Http/Response would help

public function withInlineAttachment(string $filename)
{
    return $this->withHeader('Content-Disposition', 'inline; filename="' . $filename . '"');
}

It would be nice, if this could be integrated in the existing method withFile(),

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (19 by maintainers)

Most upvoted comments

Check it first 😃 this was written and analyzed 9 years ago^^

$this->response->withFile('file.pdf', ['as' => 'inline', 'name' => 'best-thing.pdf']); This suggestion from @markstory would fit my needs. If I create a PR for that, would it be merged?

It would be nice, if this could be integrated in the existing method withFile(),

What would the interface extension to withFile look like? Would something like

$this->response->withFile('file.pdf', ['as' => 'inline', 'name' => 'best-thing.pdf']);

Work? This would also make the download => true option an alias for as => 'download'. I don’t think another boolean option is a good idea as then we have to handle the situation where both are set.