<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 - 下载文件

        symfony - download files(symfony - 下载文件)

        <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 - 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)
                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>

                        <tbody id='2jCu3'></tbody>
                      • <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>