📜  使用 CodeIgniter 上传多张图片 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:02.601000             🧑  作者: Mango

代码示例2
views
---------



Controller ---------- public function multiple_files(){ $this->load->library('upload'); $image = array(); $ImageCount = count($_FILES['image_name']['name']); for($i = 0; $i < $ImageCount; $i++){ $_FILES['file']['name'] = $_FILES['image_name']['name'][$i]; $_FILES['file']['type'] = $_FILES['image_name']['type'][$i]; $_FILES['file']['tmp_name'] = $_FILES['image_name']['tmp_name'][$i]; $_FILES['file']['error'] = $_FILES['image_name']['error'][$i]; $_FILES['file']['size'] = $_FILES['image_name']['size'][$i]; // File upload configuration $uploadPath = './assets/images/profiles/'; $config['upload_path'] = $uploadPath; $config['allowed_types'] = 'jpg|jpeg|png|gif'; // Load and initialize upload library $this->load->library('upload', $config); $this->upload->initialize($config); // Upload file to server if($this->upload->do_upload('file')){ // Uploaded file data $imageData = $this->upload->data(); $uploadImgData[$i]['image_name'] = $imageData['file_name']; } } if(!empty($uploadImgData)){ // Insert files data into the database $this->pages_model->multiple_images($uploadImgData); } } Model --------- public function multiple_images($image = array()){ return $this->db->insert_batch('profile_images',$image); }