I am working on a eCommerce based website which is selling products like T-shirts printing, Coffee Cup Printing. I want to upload multiple image files for multiple products but its not working i have attached a screenshot of my html form and also php code of that file.
Please help me to sort out this problem. Thanks in advance.
<?php
if($_POST)
{
$userid=$_SESSION['new_userid'];
$date = date("Y-m-d H:i:s");
foreach($_POST['productid'] as $row=>$productid)
{
$pid = mysql_real_escape_string($productid);
$quantity = mysql_real_escape_string($_POST['quantity'][$row]);
foreach($_FILES['file']['tmp_name'] as $key => $tmp_name )
{
$file_name = time().$_FILES['file']['name'][$key][$row];
$file_size =$_FILES['file']['size'][$key][$row];
$file_tmp =$_FILES['file']['tmp_name'][$key][$row];
$file_type=$_FILES['file']['type'][$key][$row];
if($file_size > 199097152){
$errors[]='File size must be less than 19 MB';
}
$desired_dir="uploads/orders/";
if(empty($errors)==true){
if(is_dir($desired_dir)==false){
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
}else{ // rename the file if another one exist
$new_dir="$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
}else{
print_r($errors);
}
$tempArr[] = $file_name;
}
$files_360 .= implode('*',$tempArr);
//Project images
$insert = $DB_class->insert('orders',array("userid"=>$userid,"proid"=>$pid,"quantity"=>$quantity,"images"=>$files_360,"date"=>$date,"status"=>"pending"), '');
}
}
?>