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

      <bdo id='gKGxy'></bdo><ul id='gKGxy'></ul>
    <legend id='gKGxy'><style id='gKGxy'><dir id='gKGxy'><q id='gKGxy'></q></dir></style></legend>
    <tfoot id='gKGxy'></tfoot>

  2. <i id='gKGxy'><tr id='gKGxy'><dt id='gKGxy'><q id='gKGxy'><span id='gKGxy'><b id='gKGxy'><form id='gKGxy'><ins id='gKGxy'></ins><ul id='gKGxy'></ul><sub id='gKGxy'></sub></form><legend id='gKGxy'></legend><bdo id='gKGxy'><pre id='gKGxy'><center id='gKGxy'></center></pre></bdo></b><th id='gKGxy'></th></span></q></dt></tr></i><div id='gKGxy'><tfoot id='gKGxy'></tfoot><dl id='gKGxy'><fieldset id='gKGxy'></fieldset></dl></div>
    1. Symfony BinaryFileResponse 设置文件名

      Symfony BinaryFileResponse set filename(Symfony BinaryFileResponse 设置文件名)
        <tbody id='IjSLk'></tbody>
      • <legend id='IjSLk'><style id='IjSLk'><dir id='IjSLk'><q id='IjSLk'></q></dir></style></legend>

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

            <small id='IjSLk'></small><noframes id='IjSLk'>

              <bdo id='IjSLk'></bdo><ul id='IjSLk'></ul>

                本文介绍了Symfony BinaryFileResponse 设置文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当文件由 Symfony2 控制器使用 BinaryFileResponse 响应返回时,是否可以设置自定义文件名?

                Is it possible to set a custom filename when the file is returned by a Symfony2 controller using a BinaryFileResponse response?

                推荐答案

                是的.BinaryFileResponse 类有一个方法 setContentDisposition() 将文件名作为第二个参数.

                Yes. The BinaryFileResponse class has a method setContentDisposition() that takes the file name as the second argument.

                第一个参数是文件的传送方式.如果应该提供文件供下载,它可以是 ResponseHeaderBag::DISPOSITION_ATTACHMENT(或只是字符串 "attachment"),或者 ResponseHeaderBag::DISPOSITION_INLINE(或 "inline") 如果您希望文件显示在浏览器中(例如,您可能希望对图像执行此操作).

                The first argument is the way the file should be delivered. It can be ResponseHeaderBag::DISPOSITION_ATTACHMENT (or just the string "attachment") if the file should be offered for downloading, or ResponseHeaderBag::DISPOSITION_INLINE (or "inline") if you want the file to be shown in the browser (you may want to do this with images, for example).

                完整代码示例:

                <?php
                use SymfonyComponentHttpFoundationBinaryFileResponse;
                use SymfonyComponentHttpFoundationResponseHeaderBag;
                
                $response = new BinaryFileResponse('/path/to/myfile');
                $response->setContentDisposition(
                    ResponseHeaderBag::DISPOSITION_ATTACHMENT,
                    'file_name.txt'
                );
                

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

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

                相关文档推荐

                Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                get a # from a url in php(从 php 中的 url 获取 #)
                PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)

                    <bdo id='qEAV5'></bdo><ul id='qEAV5'></ul>

                    <small id='qEAV5'></small><noframes id='qEAV5'>

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

                          <tfoot id='qEAV5'></tfoot>