Multiple file upload in Codeigniter
CodeIgniter’s File Uploading Class allows uploading files on the server. You can upload single file or image easily using core php. But sometimes multiple file uploading feature needs to be provided the in the web application. This article will help to upload multiple file and image at once using for loop. You may also like Multiple file upload in php.
Code
for($i=0; $i<count($_FILES['file']['name']); $i++) {
$tmpFilePath = $_FILES['file']['tmp_name'][$i];
$shortname = $_FILES['file']['name'][$i];
$filename = date('YmdHis').$_FILES['file']['name'][$i];
$filePath = "./public/course_work/".$filename;
$ext = pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION);
$file = basename($shortname,".".$ext);
if(move_uploaded_file($tmpFilePath, $filePath))
{
$image_array = array(
'file_name' =>$filename,
'origanal_file_name' =>$file,
'file_ext' =>$ext,
'created_date' =>date('Y-m-d H:i:s'),
);
$this->db->insert('medical_stu_course_work_file', $image_array);
}
}
Leave a Reply