$ app-> sendFile在调试模式下工作,否则失败

时间:2017-03-21 13:52:53

标签: php symfony silex

我在Silex路由器中有这条路线:

$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 );
});

它相当简单,基本上从Silex' docs逐字复制。我在调试模式下工作正常;但是,一旦我关闭调试模式,它就会给我一个"哎呀,出错了"我点击路线时出现错误信息。

我试过了:

  • 删除setContentDisposition行。
  • Streaming the file而非使用sendFile
  • 阅读其他人关于sendFile1234)的问题。

一切都无济于事。

我做错了什么?

[关于symfony标记的注意事项:我没有使用Symfony本身,但包含标记,因为我使用Symfony组件ResponseHeaderBag作为此路由的一部分。 ]

0 个答案:

没有答案
相关问题