i have multiple file upload but it only loop once and stop its mean that i get in data base only one file
i have tried to insert the db part inside the loop but its multiple rows in db and i dont want it like this
if(isset($_POST['submit'])){
$websites = $_POST['websites'];
foreach($_FILES['documents']['tmp_name'] as $key => $tmp_name){
$file_name = $key.$_FILES['documents']['name'][$key];
$file_size =$_FILES['documents']['size'][$key];
$file_tmp =$_FILES['documents']['tmp_name'][$key];
$file_type=$_FILES['documents']['type'][$key];
move_uploaded_file($file_tmp,"uploads/".time().$file_name);
}
print_r($file_name);
$pdo = DB();
$stmt = $pdo->prepare("INSERT INTO client_form_7
(client_id, documents, websites)
VALUES (:client_id, :documents, :websites)");
$stmt->bindParam("client_id", $user_id, PDO::PARAM_INT);
$stmt->bindParam("documents", $file_name, PDO::PARAM_STR);
$stmt->bindParam("websites", $websites, PDO::PARAM_STR);
$stmt->execute();
}
i want all my files stored in db as array
EDIT
my solution
just create empty array before the foreach and inside the foreach push the file name to the new array and outside encoded the array full of the file names with json_encode
and insert it to the db thank you guys for the workthrou
code
$arr = array();
foreach($_FILES['documents']['tmp_name'] as $key => $tmp_name){
$file_name = $key.$_FILES['documents']['name'][$key];
$file_size =$_FILES['documents']['size'][$key];
$file_tmp =$_FILES['documents']['tmp_name'][$key];
$file_type=$_FILES['documents']['type'][$key];
move_uploaded_file($file_tmp,"uploads/".time().$file_name);
$arr[] = $file_name;
}
$files = json_encode($arr);