Upload multiple files using php function
Get the solution ↓↓↓I have a single file upload in my functions.php file which works well.I would like to change it to upload multiple files, I have seen some video and sites that show a simple way but I'm not sure how to change my code to be similar to what I see on the web. This is my single file upload code below:
add_filter( 'submit_job_form_fields', 'frontend_add_image_field' );
function frontend_add_image_field( $fields ) {
$fields['job']['job_image'] = array(
'label' => __( 'Upload Image', 'job_manager' ),
'type' => 'file',
'required' => true,
'placeholder' => '',
'priority' => 9
);
return $fields;
}'
This is what I see on the web:
<form method='post' action='' enctype='multipart/form-data'>
<input type="file" name="file[]" id="file" multiple>
<input type='submit' name='submit' value='Upload'>
</form>
<?php
if(isset($_POST['submit'])){
// Count total files
$countfiles = count($_FILES['file']['name']);
// Looping all files
for($i=0;$i<$countfiles;$i++){
$filename = $_FILES['file']['name'][$i];
// Upload file
move_uploaded_file($_FILES['file']['tmp_name'][$i],'upload/'.$filename);
}
}
?>
HOW DO I USE THAT CODE IN MY functions.php file, I am still new to PHP, please assist.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: trying to access array offset on value of type bool
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.