1. <legend id='RoHsj'><style id='RoHsj'><dir id='RoHsj'><q id='RoHsj'></q></dir></style></legend>
    2. <small id='RoHsj'></small><noframes id='RoHsj'>

        • <bdo id='RoHsj'></bdo><ul id='RoHsj'></ul>
        <i id='RoHsj'><tr id='RoHsj'><dt id='RoHsj'><q id='RoHsj'><span id='RoHsj'><b id='RoHsj'><form id='RoHsj'><ins id='RoHsj'></ins><ul id='RoHsj'></ul><sub id='RoHsj'></sub></form><legend id='RoHsj'></legend><bdo id='RoHsj'><pre id='RoHsj'><center id='RoHsj'></center></pre></bdo></b><th id='RoHsj'></th></span></q></dt></tr></i><div id='RoHsj'><tfoot id='RoHsj'></tfoot><dl id='RoHsj'><fieldset id='RoHsj'></fieldset></dl></div>
        <tfoot id='RoHsj'></tfoot>
      1. 如何在 PHP 中强制下载文件

        How to force a file to download in PHP(如何在 PHP 中强制下载文件)
          <tbody id='pw3Yy'></tbody>

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

          • <legend id='pw3Yy'><style id='pw3Yy'><dir id='pw3Yy'><q id='pw3Yy'></q></dir></style></legend>

                <tfoot id='pw3Yy'></tfoot>

                • <bdo id='pw3Yy'></bdo><ul id='pw3Yy'></ul>

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

                  本文介绍了如何在 PHP 中强制下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有图片列表,我想要一个下载"链接以及每张图片,以便用户可以下载图片.

                  I have list of images and I want a "Download" link along with every image so that user can download the image.

                  那么有人可以指导我如何为 php 中的任何文件提供下载链接吗?

                  so can someone guide me How to Provide Download link for any file in php?

                  编辑

                  我希望在单击下载链接时显示下载面板我不想导航到要在浏览器上显示的图像

                  I want a download panel to be displayed on clicking the download link I dont want to navigate to image to be displayed on the browser

                  推荐答案

                  如果你想强制下载,你可以使用类似下面的方法:

                  If you want to force a download, you can use something like the following:

                  <?php
                      // Fetch the file info.
                      $filePath = '/path/to/file/on/disk.jpg';
                  
                      if(file_exists($filePath)) {
                          $fileName = basename($filePath);
                          $fileSize = filesize($filePath);
                  
                          // Output headers.
                          header("Cache-Control: private");
                          header("Content-Type: application/stream");
                          header("Content-Length: ".$fileSize);
                          header("Content-Disposition: attachment; filename=".$fileName);
                  
                          // Output file.
                          readfile ($filePath);                   
                          exit();
                      }
                      else {
                          die('The provided file path is not valid.');
                      }
                  ?>
                  

                  如果您只是使用普通链接链接到此脚本,则会下载该文件.

                  If you simply link to this script using a normal link the file will be downloaded.

                  顺便说一句,上面的代码片段需要在页面开始时执行(在任何标题或 HTML 输出发生之前.)如果您决定基于此创建一个用于下载任意文件的函数,也要小心- 您需要确保防止目录遍历(realpath 是方便),如果您接受来自 $_GET 或 $_POST 的输入,则仅允许从定义的区域内下载.

                  Incidentally, the code snippet above needs to be executed at the start of a page (before any headers or HTML output had occurred.) Also take care if you decide to create a function based around this for downloading arbitrary files - you'll need to ensure that you prevent directory traversal (realpath is handy), only permit downloads from within a defined area, etc. if you're accepting input from a $_GET or $_POST.

                  这篇关于如何在 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 的问题)
                • <legend id='LiPgH'><style id='LiPgH'><dir id='LiPgH'><q id='LiPgH'></q></dir></style></legend><tfoot id='LiPgH'></tfoot>
                    <bdo id='LiPgH'></bdo><ul id='LiPgH'></ul>
                      <tbody id='LiPgH'></tbody>

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

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