<legend id='f9vQU'><style id='f9vQU'><dir id='f9vQU'><q id='f9vQU'></q></dir></style></legend>
  • <small id='f9vQU'></small><noframes id='f9vQU'>

  • <tfoot id='f9vQU'></tfoot>

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

        上传多张图片并将其路径存储在数据库中

        时间:2023-07-29
          <tbody id='ewBeO'></tbody>

        • <bdo id='ewBeO'></bdo><ul id='ewBeO'></ul>

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

            <tfoot id='ewBeO'></tfoot>

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

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

                  本文介绍了上传多张图片并将其路径存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在制作一个表格,用户可以通过它上传多张图片.当用户上传图像时,它们会存储在服务器的文件夹中.直到这里一切正常,但是当我尝试将图像的路径保存在数据库中时,而不是路径,两个图像的名称仅存储在一行中.我希望每个图像的路径应该存储在不同的行中.

                  <div class="form-group"><label class="col-md-3 control-label">上传图片:</label><div class="col-md-8"><input type="file" id="file" name="support_images[]" multiple accept="image/*"/>

                  <div class="form-group"><label class="col-md-3 control-label"></label><div class="提交"><input class="btn btn-primary" value="保存" type="submit" name="submit">

                  </表单>

                  admin_insert_property_images.php

                  解决方案

                  你的 $filepath 变量和你的 query 必须在你的循环中.

                  您还使用了与 mysqli_ 函数不兼容的 mysql_query.

                  这两个 API 不能混合在一起.使用 mysqli_query 同时将数据库连接传递给它.

                  I am making a form through which user can upload multiple images. When the user uploads the images they get stored in the server's folder. Everything works fine till here but when I am trying to save the path of the images in the database then instead of the path, the name of both the images gets stored in one row only. I want that the path of each image should get stored in different row.

                  <form action="admin_insert_property_images.php" method="post" enctype="multipart/form-data">
                      <div class="form-group">
                          <label class="col-md-3 control-label">Upload Image:</label>
                              <div class="col-md-8">
                                  <input type="file" id="file" name="support_images[]" multiple accept="image/*" />
                              </div>
                      </div>
                  
                      <div class="form-group">
                          <label class="col-md-3 control-label"></label>
                              <div class="submit">
                                  <input class="btn btn-primary" value="Save " type="submit" name="submit">
                              </div>  
                      </div>
                  </form>
                  

                  admin_insert_property_images.php

                  <?php
                  $con=mysqli_connect("abc.com","abc","ab","abc");
                  // Check connection
                  if (mysqli_connect_errno()) 
                      {
                          echo "Failed to connect to MySQL: " . mysqli_connect_error();
                      }
                  
                  if(isset($_POST['submit']))           
                  {
                   extract($_POST);
                  
                      if(isset($_FILES['support_images']['name']))
                      {
                          $file_name_all="";
                          for($i=0; $i<count($_FILES['support_images']['name']); $i++) 
                          {
                                 $tmpFilePath = $_FILES['support_images']['tmp_name'][$i];    
                                 if ($tmpFilePath != "")
                                 {    
                                     $path = "propertyimages/"; // create folder 
                                     $name = $_FILES['support_images']['name'][$i];
                                    $size = $_FILES['support_images']['size'][$i];
                  
                                     list($txt, $ext) = explode(".", $name);
                                     $file= time().substr(str_replace(" ", "_", $txt), 0);
                                     $info = pathinfo($file);
                                     $filename = $file.".".$ext;
                                     if(move_uploaded_file($_FILES['support_images']['tmp_name'][$i], $path.$filename)) 
                                     { 
                                        $file_name_all.=$filename."*";
                                     }
                               }
                          }
                          $filepath = rtrim($file_name_all, '*'); 
                  $query=mysqli_query($con,"INSERT into propertyimages (`propertyimage`) VALUES('".addslashes($filepath)."'); ");    
                          }
                          else
                      {
                          $filepath="";
                      }
                  
                      if($query)
                      {
                         header("Location: admin_profile.php");
                      }
                  }
                  ?>
                  

                  解决方案

                  Your $filepath variable and your query has to be in your loop.

                  You are also using mysql_query which is not compatible with mysqli_ functions.

                  Those two APIs do not mix together. Use mysqli_query while passing DB connection to it.

                  <?php
                  $con=mysqli_connect("abc.com","abc","ab","abc");
                  // Check connection
                  if (mysqli_connect_errno()) 
                      {
                          echo "Failed to connect to MySQL: " . mysqli_connect_error();
                      }
                  
                  if(isset($_POST['submit']))           
                  {
                   extract($_POST);
                  
                      if(isset($_FILES['support_images']['name']))
                      {
                          $file_name_all="";
                          for($i=0; $i<count($_FILES['support_images']['name']); $i++) 
                          {
                                 $tmpFilePath = $_FILES['support_images']['tmp_name'][$i];    
                                 if ($tmpFilePath != "")
                                 {    
                                     $path = "propertyimages/"; // create folder 
                                     $name = $_FILES['support_images']['name'][$i];
                                    $size = $_FILES['support_images']['size'][$i];
                  
                                     list($txt, $ext) = explode(".", $name);
                                     $file= time().substr(str_replace(" ", "_", $txt), 0);
                                     $info = pathinfo($file);
                                     $filename = $file.".".$ext;
                                     if(move_uploaded_file($_FILES['support_images']['tmp_name'][$i], $path.$filename)) 
                                     { 
                                        $file_name_all.=$filename."*";
                                     }
                               }
                                $filepath = rtrim($file_name_all, '*').$path;    
                           $query=mysqli_query($con,"INSERT into propertyimages (`propertyimage`) VALUES('".addslashes($filepath)."'); ");
                          }
                  
                      }
                      else
                      {
                          $filepath="";
                      }
                  
                      if($query)
                      {
                         header("Location: admin_profile.php");
                      }
                  }
                  

                  这篇关于上传多张图片并将其路径存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:php print_r 中显示的二进制文件内容但未保存在 下一篇:通过ajax调用加载mysqli php数据

                  相关文章

                  最新文章

                1. <legend id='8x4OB'><style id='8x4OB'><dir id='8x4OB'><q id='8x4OB'></q></dir></style></legend>
                2. <small id='8x4OB'></small><noframes id='8x4OB'>

                    <bdo id='8x4OB'></bdo><ul id='8x4OB'></ul>

                        <tbody id='8x4OB'></tbody>

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