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

    1. <legend id='dYbHo'><style id='dYbHo'><dir id='dYbHo'><q id='dYbHo'></q></dir></style></legend>
        <bdo id='dYbHo'></bdo><ul id='dYbHo'></ul>

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

      1. php print_r 中显示的二进制文件内容但未保存在

        时间:2023-07-29

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

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

                • 本文介绍了php print_r 中显示的二进制文件内容但未保存在 mysql 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我必须将输入字段中的文件保存到数据库中,我会这样做:

                  i have to save the files from input fields to database,i'll do it this way:

                      $mkey = mysqli_insert_id($mysqli);
                      $i=0;
                      while (isset($_FILES['file'.$i])) {
                          $filepath = ini_get('upload_tmp_dir')."/".basename($_FILES['file'.$i]['tmp_name']);
                          $filepath = addslashes($filepath);
                          $handle = fopen($filepath, "rb");
                          $content = fread($handle, filesize($filepath));
                          $stmt = $mysqli->prepare("INSERT INTO attachment (filename,filecontent,mkey) VALUES (?,?,?)");
                          $stmt->bind_param("sbi",$_FILES['file'.$i]['name'],$content,$mkey);
                          $stmt->execute();
                          fclose($handle);
                          $i++;
                      }
                  

                  没有发生错误,其他 2 个字段 mkey 和 filename 填充在数据库列中,但内容没有,$content 在我的浏览器中显示为 print_r,我确定 $content 变量不为空,但 mysql 没有显示任何内容内容.

                  no error occured,and the other 2 fields mkey and filename are filled in database columns,but the content no,$content shown with print_r in my browser and i sure the $content variable is not empty,but mysql shows me nothing of the content.

                  推荐答案

                  RTM ;-)

                  如果变量的数据大小超过最大值.允许的数据包大小(max_allowed_pa​​cket),您必须在类型中指定 b 并使用 mysqli_stmt_send_long_data() 以包的形式发送数据.

                  If data size of a variable exceeds max. allowed packet size (max_allowed_packet), you have to specify b in types and use mysqli_stmt_send_long_data() to send the data in packets.

                  所以我自己从来没有这样做过,但我认为它需要根据您的代码和 函数文档页面上的示例:

                  So I have never done this myself but i would assume it needs to look something like this based on your code and the example on the functions doc page:

                      $filepath = ini_get('upload_tmp_dir')."/".basename($_FILES['file'.$i]['tmp_name']);
                      $filepath = addslashes($filepath);
                      $handle = fopen($filepath, "rb");
                      $content = null;
                  
                      $stmt = $mysqli->prepare("INSERT INTO attachment (filename,filecontent,mkey) VALUES (?,?,?)");
                      $stmt->bind_param("sbi",$_FILES['file'.$i]['name'], $content, $mkey);
                  
                      while (!feof($handle)) {
                          // $maxPacketSize would be the size of your max packet setting for mysql,
                          // or something safely assumed to be below it
                          $stmt->send_long_data(1, fread($handle, $maxPacketSize));
                      }
                      fclose($handle);
                      $stmt->execute();
                  

                  这篇关于php print_r 中显示的二进制文件内容但未保存在 mysql 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:对现有密码使用 password_verify 下一篇:上传多张图片并将其路径存储在数据库中

                  相关文章

                  最新文章

                  <tfoot id='XGTaS'></tfoot>
                  • <bdo id='XGTaS'></bdo><ul id='XGTaS'></ul>
                  <legend id='XGTaS'><style id='XGTaS'><dir id='XGTaS'><q id='XGTaS'></q></dir></style></legend>

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

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