Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查是否在php中的字段数组中选择了文件_Php_Multiple File Upload - Fatal编程技术网

检查是否在php中的字段数组中选择了文件

检查是否在php中的字段数组中选择了文件,php,multiple-file-upload,Php,Multiple File Upload,我必须更新由多个文件输入类型字段组成的数据库。 所有输入字段的名称都相同 <input type="text" name="title[]"> <input type="file" name="image[]"> <input type="text" name="title[]"> <input type="file" name="image[]"> <input type="text" name="title[]"> <inpu

我必须更新由多个文件输入类型字段组成的数据库。 所有输入字段的名称都相同

<input type="text" name="title[]">
<input type="file" name="image[]">
<input type="text" name="title[]">
<input type="file" name="image[]">
<input type="text" name="title[]">
<input type="file" name="image[]">

第二个输入字段中的选定图像

首先,如果($upload=1),则需要将代码中的
=
更改为
=
。因为
=
赋值
运算符而不是
比较
运算符

检查一下,也许你的问题已经解决了。否则,请检查以下可能的解决方案

1.

<?php
  $title = $_POST['title'];

for($i=0; $i<sizeof($title); $i++)
{
   if(!empty($_FILES['image']['name'][$i]))
   {
       // check if file uploaded then run below query
        $qry = "UPDATE <table_name> SET title='$title[$i]', image='$image' WHERE <match found>"; // you can apply if else here based on move_uploaded_file output       
   } else {
       // set flag upload=0
        $qry = "UPDATE <table_name> SET title='$title[$i]' WHERE <match found>";
   }
}
?>
<?php
  $title = $_POST['title'];
    $upload = 0; // define here
for($i=0; $i<sizeof($title); $i++)
{
   if(!empty($_FILES['image']['name'][$i]))
   {
       // upload file and set flag $upload = 1
   } else {
       // set flag $upload = 0
   }

   if($upload == 1) // you need to change = (assignment) to  == (comparision)
   {
      $qry = "UPDATE <table_name> SET title='$title[$i]', image='$image' WHERE <match found>";
      // execute $qry
   } else {
      $qry = "UPDATE <table_name> SET title='$title[$i]' WHERE <match found>";
      // execute $qry
   }
}
?>

我已经更正了有问题的代码(那是打字错误)。实际上,我试着在if条件下打印
echoif(!empty($_FILES['image'][$i]){echo'in if condition…';}
中的code>if(!empty($_FILES['image'][$i]){echo'in if condition…}
但它不打印任何内容..首先尝试检查
echo';打印(美元文件)在任何条件之前。并检查显示的内容?我已经用
print\r($\u文件)的结果更新了问题
。您还必须在那里添加
['name']
。请检查我编辑的答案
<?php
  $title = $_POST['title'];

for($i=0; $i<sizeof($title); $i++)
{
   if(!empty($_FILES['image']['name'][$i]))
   {
       // check if file uploaded then run below query
        $qry = "UPDATE <table_name> SET title='$title[$i]', image='$image' WHERE <match found>"; // you can apply if else here based on move_uploaded_file output       
   } else {
       // set flag upload=0
        $qry = "UPDATE <table_name> SET title='$title[$i]' WHERE <match found>";
   }
}
?>
<?php
  $title = $_POST['title'];
    $upload = 0; // define here
for($i=0; $i<sizeof($title); $i++)
{
   if(!empty($_FILES['image']['name'][$i]))
   {
       // upload file and set flag $upload = 1
   } else {
       // set flag $upload = 0
   }

   if($upload == 1) // you need to change = (assignment) to  == (comparision)
   {
      $qry = "UPDATE <table_name> SET title='$title[$i]', image='$image' WHERE <match found>";
      // execute $qry
   } else {
      $qry = "UPDATE <table_name> SET title='$title[$i]' WHERE <match found>";
      // execute $qry
   }
}
?>