如何将多个图像上传到PHP和Mysql中

如何将多个图像上传到PHP和Mysql中,php,html,Php,Html,大家好, 我有一个由10列组成的表,其中4列我想插入图像路径。 有谁能指导我如何在一次查询中将图像路径和其他6列数据一起插入数据库,并将图像上载到服务器(文件夹内) 这里是我的html代码: <div class="panel-body"> <div class="form-group"> <label style="align-content:center" for="inputdefault">Product full name</labe

大家好,
我有一个由10列组成的表,其中4列我想插入图像路径。
有谁能指导我如何在一次查询中将图像路径和其他6列数据一起插入数据库,并将图像上载到服务器(文件夹内)

这里是我的html代码:

<div class="panel-body">
<div class="form-group">
    <label style="align-content:center" for="inputdefault">Product full name</label>
    <input class="form-control" id="inputdefault" name="name2" type="text">
</div>

产品全称


产品类别


产品数量


图1。
图2。
图3。
图4。

这里是php代码: 注意:我并没有在任何变量中获得图像文件名来添加到查询中,这里的一切都正常,只需要使用图像上传并将路径存储到数据库中

<?php

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$pname= stripslashes($_REQUEST['name1']);
$pcat= stripslashes($_REQUEST['name2']);
$pprice= stripslashes($_REQUEST['name3']);
$pqty= stripslashes($_REQUEST['qty']);
$pdesc=stripslashes($_REQUEST['description']);
//$spassword=stripslashes($_REQUEST['img']);



$sqlinsert ="INSERT INTO `noorizone`.`products` VALUES ('$pname', '$pcat', '$pprice')";

    if($con-> query($sqlinsert)=== true)
{
    echo "<center><b style='color:green;'> added  successfully... </b>";
    echo"</center>";
}
else{
    echo "<b style='color:red;'> cant register". $con->error."</b>";
}
}
?>

这是我的示例,您可以学习我的代码:

$fileImageStatus = "";                      // Create your variable for files
if(isset($_FILES['files_status']['name'])){ // Checking value for all input
  $fileImageName = array();                 // Make an array
  for($i = 0; $i < count($_FILES['files_status']['name']); $i++){ // Looping
      $imageName = $_FILES['files_status']['name'][$i];         // Give a variable with index from array looped
      $uploadPath = '././sistem/users/members/'.$idPenerima.'/unggahan/';
      move_uploaded_file($imageTmp, $uploadPath.$imageName);    // Path upload
      $fileImageName[] = $imageName;                           // Setting a values from array
  }
      $fileImageStatus = implode(",", $fileImageName);         // Make that values an string
   }
  // in here you can insert to database with value from $fileImageStatus
$fileImageStatus=”“;//为文件创建变量
如果(isset($\u FILES['FILES\u status']['name']){//检查所有输入的值
$fileImageName=array();//创建一个数组
对于($i=0;$i
这是一个关于如何将多个图像上传到PHP和Mysql的好教程


我想如果你把文件名改为file1而不是file[],你会没事的

看一个例子


选择要上载的图像:

你没有任何意义。您刚刚复制并粘贴了此代码。OP显然是php的新手。添加解释,否则人们会往下看,因为我们有一个自己的忙。好的,我给你打个电话explanation@Akintunde你能详细回答吗explanation@user8455694thnks我知道了,让我应用一次。@user8455694你能把代码更新成我自己写的代码吗,我试过了,但没有完全理解,thnks我也看到了,但我要求多个文件上传
<div class="panel-body">
<div class="form-group">
    <label style="align-content:center" for="inputdefault">Picture 1.</label>
    <input type="file" id="file3" name="files[]" multiple="multiple" accept="image/*" />
</div>
<div class="form-group">
    <label style="align-content:center" for="inputdefault">Picture 2.</label>
    <input type="file" id="file3" name="files[]" multiple="multiple" accept="image/*" />
</div>
<div class="form-group">
    <label style="align-content:center" for="inputdefault">Picture 3.</label>
    <input type="file" id="file3" name="files[]" multiple="multiple" accept="image/*" />
</div>
<div class="form-group">
    <label style="align-content:center" for="inputdefault">Picture 4.</label>
    <input type="file" id="file3" name="files[]" multiple="multiple" accept="image/*" />
</div>
<?php

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$pname= stripslashes($_REQUEST['name1']);
$pcat= stripslashes($_REQUEST['name2']);
$pprice= stripslashes($_REQUEST['name3']);
$pqty= stripslashes($_REQUEST['qty']);
$pdesc=stripslashes($_REQUEST['description']);
//$spassword=stripslashes($_REQUEST['img']);



$sqlinsert ="INSERT INTO `noorizone`.`products` VALUES ('$pname', '$pcat', '$pprice')";

    if($con-> query($sqlinsert)=== true)
{
    echo "<center><b style='color:green;'> added  successfully... </b>";
    echo"</center>";
}
else{
    echo "<b style='color:red;'> cant register". $con->error."</b>";
}
}
?>
$fileImageStatus = "";                      // Create your variable for files
if(isset($_FILES['files_status']['name'])){ // Checking value for all input
  $fileImageName = array();                 // Make an array
  for($i = 0; $i < count($_FILES['files_status']['name']); $i++){ // Looping
      $imageName = $_FILES['files_status']['name'][$i];         // Give a variable with index from array looped
      $uploadPath = '././sistem/users/members/'.$idPenerima.'/unggahan/';
      move_uploaded_file($imageTmp, $uploadPath.$imageName);    // Path upload
      $fileImageName[] = $imageName;                           // Setting a values from array
  }
      $fileImageStatus = implode(",", $fileImageName);         // Make that values an string
   }
  // in here you can insert to database with value from $fileImageStatus