<bdo id='uownt'></bdo><ul id='uownt'></ul>
    <legend id='uownt'><style id='uownt'><dir id='uownt'><q id='uownt'></q></dir></style></legend>
    <tfoot id='uownt'></tfoot>
    <i id='uownt'><tr id='uownt'><dt id='uownt'><q id='uownt'><span id='uownt'><b id='uownt'><form id='uownt'><ins id='uownt'></ins><ul id='uownt'></ul><sub id='uownt'></sub></form><legend id='uownt'></legend><bdo id='uownt'><pre id='uownt'><center id='uownt'></center></pre></bdo></b><th id='uownt'></th></span></q></dt></tr></i><div id='uownt'><tfoot id='uownt'></tfoot><dl id='uownt'><fieldset id='uownt'></fieldset></dl></div>

    1. <small id='uownt'></small><noframes id='uownt'>

        symfony - 下载文件

        时间:2023-11-30

        <tfoot id='0euzp'></tfoot>

        <small id='0euzp'></small><noframes id='0euzp'>

        1. <i id='0euzp'><tr id='0euzp'><dt id='0euzp'><q id='0euzp'><span id='0euzp'><b id='0euzp'><form id='0euzp'><ins id='0euzp'></ins><ul id='0euzp'></ul><sub id='0euzp'></sub></form><legend id='0euzp'></legend><bdo id='0euzp'><pre id='0euzp'><center id='0euzp'></center></pre></bdo></b><th id='0euzp'></th></span></q></dt></tr></i><div id='0euzp'><tfoot id='0euzp'></tfoot><dl id='0euzp'><fieldset id='0euzp'></fieldset></dl></div>
              <bdo id='0euzp'></bdo><ul id='0euzp'></ul>

                    <tbody id='0euzp'></tbody>
                  <legend id='0euzp'><style id='0euzp'><dir id='0euzp'><q id='0euzp'></q></dir></style></legend>
                1. 本文介绍了symfony - 下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在控制器中下载文件,但在控制台中我只看到一堆奇怪的字符而不是下载框.我正在关注这个主题 Symfony2 - 强制文件下载.

                  I am trying download files in controller but in the console I see only really bunch of weird characters instead of download box. I am following this topic Symfony2 - Force file download.

                  不知道发生了什么...试图找到最简单的解决方案.这是我的代码:

                  Don't know what is going on... trying to find simplest solution. Here is my code:

                   $response = new Response(file_get_contents($file->realPath), 200, array(
                              'Content-Type' => $file->mimeType,
                              'Content-Length' => filesize($file->realPath),
                              'Content-Disposition' => 'attachment; filename=' . $file->name,
                          ));
                   $response->send();
                  

                  我什至尝试使用带有 header() 和 readfile() 的最基本示例.我的服务器需要特殊配置吗?干杯.

                  I've even tried to use the most basic example with header() and readfile(). Does my server need special config or something? Cheers.

                  推荐答案

                  您可以使用 Symfony 的内置BinaryFileResponse,而不是重建这种响应.

                  Instead of rebuilding that kind of response, you could use Symfony's built-inBinaryFileResponse.

                  use SymfonyComponentHttpFoundationBinaryFileResponse;
                  
                  $response = new BinaryFileResponse($file);
                  

                  还请查看关于提供文件的文档.

                  这篇关于symfony - 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:当 header(Location: xxx) 在里面时 PHP if 语句被忽略 下一篇:PHP-“标头已发送"错误取决于输出长度?

                  相关文章

                2. <legend id='2jCu3'><style id='2jCu3'><dir id='2jCu3'><q id='2jCu3'></q></dir></style></legend>
                    <bdo id='2jCu3'></bdo><ul id='2jCu3'></ul>

                  1. <small id='2jCu3'></small><noframes id='2jCu3'>

                    1. <i id='2jCu3'><tr id='2jCu3'><dt id='2jCu3'><q id='2jCu3'><span id='2jCu3'><b id='2jCu3'><form id='2jCu3'><ins id='2jCu3'></ins><ul id='2jCu3'></ul><sub id='2jCu3'></sub></form><legend id='2jCu3'></legend><bdo id='2jCu3'><pre id='2jCu3'><center id='2jCu3'></center></pre></bdo></b><th id='2jCu3'></th></span></q></dt></tr></i><div id='2jCu3'><tfoot id='2jCu3'></tfoot><dl id='2jCu3'><fieldset id='2jCu3'></fieldset></dl></div>
                      <tfoot id='2jCu3'></tfoot>