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

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

      <tfoot id='n3XsR'></tfoot>
        <legend id='n3XsR'><style id='n3XsR'><dir id='n3XsR'><q id='n3XsR'></q></dir></style></legend>

        php - 如何强制下载文件?

        php - How to force download of a file?(php - 如何强制下载文件?)
        • <bdo id='06zH8'></bdo><ul id='06zH8'></ul>

          <tfoot id='06zH8'></tfoot>

            <small id='06zH8'></small><noframes id='06zH8'>

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

                    <tbody id='06zH8'></tbody>
                  本文介绍了php - 如何强制下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望在我的一个网站上的每个视频下方添加下载此文件"功能.我需要强制用户下载文件,而不仅仅是链接到它,因为有时会开始在浏览器中播放文件.问题是,视频文件存储在单独的服务器上.

                  I'm looking to add a "Download this File" function below every video on one of my sites. I need to force the user to download the file, instead of just linking to it, since that begins playing a file in the browser sometimes. The problem is, the video files are stored on a separate server.

                  有什么办法可以强制在 PHP 中下载吗?

                  Any way I can force the download in PHP?

                  推荐答案

                  你可以试试这样的:

                  $file_name = 'file.avi';
                  $file_url = 'http://www.myremoteserver.com/' . $file_name;
                  header('Content-Type: application/octet-stream');
                  header("Content-Transfer-Encoding: Binary"); 
                  header("Content-disposition: attachment; filename="".$file_name."""); 
                  readfile($file_url);
                  exit;
                  

                  我刚刚测试了它,它对我有用.

                  I just tested it and it works for me.

                  请注意,要使 readfile 能够读取远程 url,您需要拥有 fopen_wrappers 已启用.

                  Please note that for readfile to be able to read a remote url, you need to have your fopen_wrappers enabled.

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

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                  <i id='d87Us'><tr id='d87Us'><dt id='d87Us'><q id='d87Us'><span id='d87Us'><b id='d87Us'><form id='d87Us'><ins id='d87Us'></ins><ul id='d87Us'></ul><sub id='d87Us'></sub></form><legend id='d87Us'></legend><bdo id='d87Us'><pre id='d87Us'><center id='d87Us'></center></pre></bdo></b><th id='d87Us'></th></span></q></dt></tr></i><div id='d87Us'><tfoot id='d87Us'></tfoot><dl id='d87Us'><fieldset id='d87Us'></fieldset></dl></div>

                    • <tfoot id='d87Us'></tfoot>

                      <legend id='d87Us'><style id='d87Us'><dir id='d87Us'><q id='d87Us'></q></dir></style></legend>
                        <tbody id='d87Us'></tbody>
                        <bdo id='d87Us'></bdo><ul id='d87Us'></ul>
                          1. <small id='d87Us'></small><noframes id='d87Us'>