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

    2. <legend id='KgvAK'><style id='KgvAK'><dir id='KgvAK'><q id='KgvAK'></q></dir></style></legend>
      <tfoot id='KgvAK'></tfoot>

      1. 通过 PHP 脚本将文件从 FTP 服务器下载到带有 Content-Length 标头的浏览器,而无需将文件存储在 W

        Download file via PHP script from FTP server to browser with Content-Length header without storing the file on the web server(通过 PHP 脚本将文件从 FTP 服务器下载到带有 Content-Length 标头的浏览器,而无需将文件存储在 Web 服务器上) - IT屋-程

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

      2. <tfoot id='Jk5c0'></tfoot>
        <legend id='Jk5c0'><style id='Jk5c0'><dir id='Jk5c0'><q id='Jk5c0'></q></dir></style></legend>

            <tbody id='Jk5c0'></tbody>

            1. <i id='Jk5c0'><tr id='Jk5c0'><dt id='Jk5c0'><q id='Jk5c0'><span id='Jk5c0'><b id='Jk5c0'><form id='Jk5c0'><ins id='Jk5c0'></ins><ul id='Jk5c0'></ul><sub id='Jk5c0'></sub></form><legend id='Jk5c0'></legend><bdo id='Jk5c0'><pre id='Jk5c0'><center id='Jk5c0'></center></pre></bdo></b><th id='Jk5c0'></th></span></q></dt></tr></i><div id='Jk5c0'><tfoot id='Jk5c0'></tfoot><dl id='Jk5c0'><fieldset id='Jk5c0'></fieldset></dl></div>
              • <bdo id='Jk5c0'></bdo><ul id='Jk5c0'></ul>
                  本文介绍了通过 PHP 脚本将文件从 FTP 服务器下载到带有 Content-Length 标头的浏览器,而无需将文件存储在 Web 服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用此代码从 ftp 将文件下载到内存:

                  I use this code to download a file to memory from ftp:

                  public static function getFtpFileContents($conn_id , $file)
                  {
                      ob_start();
                      $result = ftp_get($conn_id, "php://output", $file, FTP_BINARY);
                      $data = ob_get_contents();
                      ob_end_clean();
                      if ($resul)
                          return $data;
                      return null;
                  }
                  

                  如何让它直接将文件发送给用户(浏览器)而不保存到磁盘并且不重定向到 ftp 服务器?

                  How can I make it directly send the file to the user (browser) without saving to disk and without redirecting to the ftp server ?

                  推荐答案

                  只需去掉输出缓冲(ob_start() 等).

                  Just remove the output buffering (ob_start() and the others).

                  只用这个:

                  ftp_get($conn_id, "php://output", $file, FTP_BINARY);
                  

                  <小时>

                  虽然如果要添加 Content-Length 标头,则必须先使用 ftp_size 查询文件大小:


                  Though if you want to add Content-Length header, you have to query file size first using ftp_size:

                  $conn_id = ftp_connect("ftp.example.com");
                  ftp_login($conn_id, "username", "password");
                  ftp_pasv($conn_id, true);
                  
                  $file_path = "remote/path/file.zip";
                  $size = ftp_size($conn_id, $file_path);
                  
                  header("Content-Type: application/octet-stream");
                  header("Content-Disposition: attachment; filename=" . basename($file_path));
                  header("Content-Length: $size"); 
                  
                  ftp_get($conn_id, "php://output", $file_path, FTP_BINARY);
                  

                  (添加错误处理)

                  有关更广泛的背景,请参阅:
                  列出并从 FTP 下载点击的文件

                  这篇关于通过 PHP 脚本将文件从 FTP 服务器下载到带有 Content-Length 标头的浏览器,而无需将文件存储在 Web 服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='B53ve'><tr id='B53ve'><dt id='B53ve'><q id='B53ve'><span id='B53ve'><b id='B53ve'><form id='B53ve'><ins id='B53ve'></ins><ul id='B53ve'></ul><sub id='B53ve'></sub></form><legend id='B53ve'></legend><bdo id='B53ve'><pre id='B53ve'><center id='B53ve'></center></pre></bdo></b><th id='B53ve'></th></span></q></dt></tr></i><div id='B53ve'><tfoot id='B53ve'></tfoot><dl id='B53ve'><fieldset id='B53ve'></fieldset></dl></div>
                  <tfoot id='B53ve'></tfoot>
                    <tbody id='B53ve'></tbody>

                  <legend id='B53ve'><style id='B53ve'><dir id='B53ve'><q id='B53ve'></q></dir></style></legend>

                      • <bdo id='B53ve'></bdo><ul id='B53ve'></ul>
                      • <small id='B53ve'></small><noframes id='B53ve'>