@elisha_langworth
To upload 2 separate images in CodeIgniter, you can follow these steps:
1 2 3 4 5 |
<form method="post" action="<?php echo base_url('upload/upload_images'); ?>" enctype="multipart/form-data"> <input type="file" name="image1"> <input type="file" name="image2"> <button type="submit">Upload Images</button> </form> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Upload extends CI_Controller { public function upload_images() { // Set upload configuration $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $this->load->library('upload', $config); // Upload image1 if ($this->upload->do_upload('image1')) { $image1_data = $this->upload->data(); $image1_path = $image1_data['file_name']; } // Upload image2 if ($this->upload->do_upload('image2')) { $image2_data = $this->upload->data(); $image2_path = $image2_data['file_name']; } // Save the file paths to the database or do something else with them } } |
By following these steps, you should be able to upload 2 separate images in CodeIgniter.