I have this route in my Silex router:
$app->get( "/route", function () use ( $app ) {
$path = __DIR__ . "/../path/to/files/dir";
$files=glob("$path/*.*");
sort($files);
$files = array_reverse($files);
$newestFile = $files[0];
$newestBasename = basename($newestFile);
return $app
->sendFile( $newestFile )
->setContentDisposition( ResponseHeaderBag::DISPOSITION_ATTACHMENT, $newestBasename );
});
It's fairly straightforward, copied basically verbatim from Silex' docs. It works fine when I'm in debug mode; but, as soon as I turn off debug mode, it gives me a "Whoops, something went wrong" error message when I hit the route.
I've tried:
- Removing the
setContentDisposition
line. - Streaming the file instead of using
sendFile
. - Reading other people's questions about
sendFile
(1, 2, 3, 4).
All to no avail.
What am I doing wrong?
[ Note regarding symfony
tag: I'm not using Symfony per-se, but included the tag since I am using the Symfony component ResponseHeaderBag
as part of this route. ]