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

        <small id='2ey8P'></small><noframes id='2ey8P'>

      1. <legend id='2ey8P'><style id='2ey8P'><dir id='2ey8P'><q id='2ey8P'></q></dir></style></legend>
        <tfoot id='2ey8P'></tfoot>
          <bdo id='2ey8P'></bdo><ul id='2ey8P'></ul>

      2. 使用 Blob 将图像上传到 MySQL 数据库

        时间:2023-09-25
          <bdo id='LKzXJ'></bdo><ul id='LKzXJ'></ul>
          • <legend id='LKzXJ'><style id='LKzXJ'><dir id='LKzXJ'><q id='LKzXJ'></q></dir></style></legend>

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

                  <tbody id='LKzXJ'></tbody>

                1. <tfoot id='LKzXJ'></tfoot>

                2. 本文介绍了使用 Blob 将图像上传到 MySQL 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  首先澄清一下,我知道有更好的方法可以做到这一点,但我决心进行实验.

                  Just to first clarify, I know there are better ways to do this, but I'm determined to experiment.

                  基本上,我试图从表单帖子中获取图像,然后将其发送到数据库 MEDIUMBLOB 字段中.

                  Basically, I'm trying to grab an image from a form post, then send that into a database MEDIUMBLOB field.

                  不幸的是,使用我当前的方法,数据库列中的最终结果始终为零字节.

                  Unfortunately, using my current method, the end result in the database column is always zero bytes. phpMyAdmin Screenshot

                  这里是表单上传图片的代码:

                  Here is the code for the image upload on the form:

                  input type="file" name="_imagePost">
                  

                  这是页面上的 PHP 代码,我使用的是 MySQLi :

                  Here is the PHP code on the page, I'm using MySQLi :

                      if(isset($_POST['_imagePost']))
                      {
                          $_useImagePost = 1;
                          $_imagePost = file_get_contents($_FILES['_imagePost']);
                  
                          // Open DB Connection
                          $_conn = databaseConnect();
                  
                          $_stmt = $_conn->prepare("INSERT INTO Question (Question_Type, Question_Text, Question_Answer, Question_UseImage, Question_Image) VALUES (?, ?, ?, ?, ?)");
                          $_stmt->bind_param("sssib", $_typePost, $_textPost, $_answerPost, $_useImagePost, $_null);
                          $_stmt->send_long_data(4,$_imagePost);
                          $_stmt->execute();
                  
                          // Close DB Connection
                          $_conn->close();
                      }
                  

                  我不确定的是,当输入类型为文件时,isset($_POST['_imagePost'])"是否有效.

                  What I am unsure of is if "isset($_POST['_imagePost'])" works when the input type is file.

                  然而,我可以肯定的是,当前的设置根本不起作用.

                  What I am sure of, however, is that the current setup doesn't work at all.

                  推荐答案

                  你写的:

                  $_imagePost = file_get_contents($_FILES['_imagePost']);
                  

                  正确的语法是:

                  $_imagePost = file_get_contents($_FILES['_imagePost']['tmp_name']);
                  

                  $_FILES 是一个带有以下键的关联数组:

                  $_FILES is an associative array whit following keys:

                  • [name] => 原始文件名;
                  • [type] => 上传文件的 mimetype;
                  • [tmp_name] => 临时文件路径(上传文件的存储位置);
                  • [错误] => 错误;
                  • [size] => 上传文件的大小.
                  • 查看更多关于$_FILES

                  这篇关于使用 Blob 将图像上传到 MySQL 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将 PDO 转换为 mysqli? 下一篇:尝试使用 MySQLi 时内存耗尽

                  相关文章

                  最新文章

                  <small id='35oKA'></small><noframes id='35oKA'>

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

                  1. <legend id='35oKA'><style id='35oKA'><dir id='35oKA'><q id='35oKA'></q></dir></style></legend>

                    <tfoot id='35oKA'></tfoot>
                      • <bdo id='35oKA'></bdo><ul id='35oKA'></ul>