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

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <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'>