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

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

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

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

      1. 从 MySQL 流式传输二进制文件以使用 PHP 下载

        时间:2023-08-20
        <tfoot id='VWAvI'></tfoot>
          • <bdo id='VWAvI'></bdo><ul id='VWAvI'></ul>

            • <small id='VWAvI'></small><noframes id='VWAvI'>

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

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

                  本文介绍了从 MySQL 流式传输二进制文件以使用 PHP 下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我将 Excel 电子表格存储在 MySQL 表 longblob 字段中.我需要检索这些数据,然后将其作为可下载文件流式传输给用户,最好不要先将其写入磁盘.

                  I have Excel spreadsheets stored in a MySQL table longblob field. I need to retrieve this data and then stream it to the user as a downloadable file, preferably without writing it to disk first.

                  可能吗?

                  编辑 - 嗯,刚刚想通了......发布在下面的答案中.

                  Edit - Eh, just figured it out... Posted in answer below.

                  推荐答案

                  function getfile($blockid)
                  {
                      global $msa_db;
                      $sql = "select filename, filedata from blocks where blockid = '$blockid'";
                      $query = mysql_query($sql, $msa_db);
                      $result['filename'] = mysql_result($query,0,0);
                      $result['filedata'] = mysql_result($query,0,1);
                      return $result;
                  
                  }
                  
                  function download($fileinfo)
                  {
                      $file = base64_decode($fileinfo['filedata']);
                      header("Cache-Control: no-cache private");
                      header("Content-Description: File Transfer");
                      header('Content-disposition: attachment; filename='.$fileinfo['filename']);
                      header("Content-Type: application/vnd.ms-excel");
                      header("Content-Transfer-Encoding: binary");
                      header('Content-Length: '. strlen($file));
                      echo $file;
                      exit;
                  }
                  
                  $fileinfo = getfile($blockid);
                  
                  download($fileinfo);
                  

                  这篇关于从 MySQL 流式传输二进制文件以使用 PHP 下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 PHP 下载远程文件到服务器 下一篇:php限制对目录中文件的访问

                  相关文章

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

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

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

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