How can I access and upload an image file within a foreach loop, given that I'm currently unable to access the file even though the array from the POST request is working?
function Products($data)
{
foreach ($data as $row) {
$product_id = $row['product_id'];
$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_tmp = $_FILES['file']['tmp_name'];
$file_type = $_FILES['file']['type'];
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
$expensions = array("jpeg", "jpg", "png", "JPEG", "JPG", "PNG");
$fileName = date('Ymdhis').".".$file_ext;
// Insert Sample Function
InsertFunction($fileName, $product_id);
}
}
$array = array(
array('product_id' => 1, 'file' => /*$_FILES 1*/),
array('product_id' => 2, 'file' => /*$_FILES 2*/),
);
echo json_encode(Products($array));
I tried to pass the file variable on the $_FILES but it was not working.