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

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

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

        如何使用php将图像存储在mysql数据库中

        时间:2023-05-21
        • <tfoot id='Hlj1v'></tfoot>
              <legend id='Hlj1v'><style id='Hlj1v'><dir id='Hlj1v'><q id='Hlj1v'></q></dir></style></legend>
              • <bdo id='Hlj1v'></bdo><ul id='Hlj1v'></ul>

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

                    <tbody id='Hlj1v'></tbody>
                1. 本文介绍了如何使用php将图像存储在mysql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  如何在 MySQL 数据库中存储和显示图像.到目前为止,我只编写了从用户那里获取图像并将它们存储在一个文件夹中的代码,我编写到现在的代码是:HTML 文件

                  How can i store and display the images in a MySQL database. Till now i have only written the code to get the images from the user and store them in a folder, the code that i wrote till now is: HTML FILE

                  <input type="file" name="imageUpload" id="imageUpload">
                  

                  PHP 文件

                      $target_dir = "uploads/";
                  $target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);
                  $uploadOk = 1;
                  $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
                  
                  
                  if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {
                      echo "The file ". basename( $_FILES["imageUpload"]["name"]). " has been uploaded.";
                  } else {
                      echo "Sorry, there was an error uploading your file.";}
                  

                  推荐答案

                  我找到了答案,对于那些在这里寻找同样事情的人,我就是这样做的.您不应该考虑将图像上传到数据库,而是可以将上传文件的名称存储在数据库中,然后检索文件名并在您想要显示图像的任何地方使用它.

                  I found the answer, For those who are looking for the same thing here is how I did it. You should not consider uploading images to the database instead you can store the name of the uploaded file in your database and then retrieve the file name and use it where ever you want to display the image.

                  HTML 代码

                  <input type="file" name="imageUpload" id="imageUpload">
                  

                  PHP 代码

                  if(isset($_POST['submit'])) {
                  
                      //Process the image that is uploaded by the user
                  
                      $target_dir = "uploads/";
                      $target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);
                      $uploadOk = 1;
                      $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
                  
                      if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {
                          echo "The file ". basename( $_FILES["imageUpload"]["name"]). " has been uploaded.";
                      } else {
                          echo "Sorry, there was an error uploading your file.";
                      }
                  
                      $image=basename( $_FILES["imageUpload"]["name"],".jpg"); // used to store the filename in a variable
                  
                      //storind the data in your database
                      $query= "INSERT INTO items VALUES ('$id','$title','$description','$price','$value','$contact','$image')";
                      mysql_query($query);
                  
                      require('heading.php');
                      echo "Your add has been submited, you will be redirected to your account page in 3 seconds....";
                      header( "Refresh:3; url=account.php", true, 303);
                  }
                  

                  显示图像的代码

                  while($row = mysql_fetch_row($result)) {
                      echo "<tr>";
                      echo "<td><img src='uploads/$row[6].jpg' height='150px' width='300px'></td>";
                      echo "</tr>
                  ";
                  }
                  

                  这篇关于如何使用php将图像存储在mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 PHP 重命名上传的文件但保留扩展名 下一篇:PHPExcel 阅读器——需要帮助

                  相关文章

                  最新文章

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

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

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

                      <tfoot id='LYASK'></tfoot>