如何在php $ _FILES变量中添加额外的参数

I have an multiple images upload page. The thing is when am updating the previously uploaded image. The images uploaded before have their own ID on database. So, when I hit update POST not all images out of 5 not set for example.

Dump => array(1) {
  ["editproductimages"] => array(5) {
    ["name"] => array(5) {
      [0] => string(0) ""
      [1] => string(11) "desktop.jpg"
      [2] => string(40) "12071419_404680519720527_756783084_n.jpg"
      [3] => string(0) ""
      [4] => string(0) ""
    }
    ["type"] => array(5) {
      [0] => string(0) ""
      [1] => string(10) "image/jpeg"
      [2] => string(10) "image/jpeg"
      [3] => string(0) ""
      [4] => string(0) ""
    }
    ["tmp_name"] => array(5) {
      [0] => string(0) ""
      [1] => string(25) "/opt/lampp/temp/phpYJDIAO"
      [2] => string(25) "/opt/lampp/temp/phpmyxoXB"
      [3] => string(0) ""
      [4] => string(0) ""
    }
    ["error"] => array(5) {
      [0] => int(4)
      [1] => int(0)
      [2] => int(0)
      [3] => int(4)
      [4] => int(4)
    }
    ["size"] => array(5) {
      [0] => int(0)
      [1] => int(55203)
      [2] => int(33773)
      [3] => int(0)
      [4] => int(0)
    }
  }
}

The thing I want is to add extract array field inside the $_FILE like to hold their database id on post.

["id"] => array(5) {
          [0] => int(10)
          [1] => int(11)
          [2] => int(12)
          [3] => int(14)
          [4] => int(13)
       }

is that possible?

I am not thinking that this is the correct approach or correct answer but I think array_push might help you since $_FILES is also an array.

lets say this is the files data.

$filesData = array(
        array('editproductimages'=>array(
                array("name"=>array("","desktop.jpg","12071419_404680519720527_756783084_n.jpg","","")),
                array("type"=> array("","image/jpeg","image/jpeg","","")),
                array("tmp_name"=>array("","/opt/lampp/temp/phpYJDIAO","/opt/lampp/temp/phpmyxoXB","","")),
                array("error"=>array(4,0,0,4,4)),
                array("size"=>array(0,55203,33773,0,0))
            ))
    );

then the array($ids) below is what you want to be added.You just need to use array_push to add it.

    $ids = array('id'=>array(10,11,12,14,13));
    //actual insertion of $ids to the $filesData variable
    array_push($filesData[0]['editproductimages'],$ids);
    echo '<pre>';
    var_dump($filesData);
    echo '</pre>';

I hope that helps

You can do it like this, lets say you have this form

<form action="">
    <!-- For your first image  -->
    <input type="hidden" name="image_ids[]" value="<?php ..place first image id.. ?>" />
    <input type="file" name="image[]"/>

    <!-- For your second image  -->
    <input type="hidden" name="image_ids[]" value="<?php ..place second image id.. ?>" />
    <input type="file" name="image[]"/>

    <!-- For your third image  -->
    <input type="hidden" name="image_ids[]" value="<?php ..place third image id.. ?>" />
    <input type="file" name="image[]"/>

    .....
</form>

after submitting this form to php you will have same sequence of values in $_FILE['image'] and $_POST['image'] arrays and you can make loop

foreach($_POST['image_ids'] as $k => $id){
    // process and save $_FILE['image'][$k] 
    // use $id to save/update necessary values in db
}