@adan
To use multiple images in CodeIgniter, you can follow these steps:
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 |
public function upload_images() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$image_data = array();
$files = $_FILES;
foreach ($files['userfile']['name'] as $key => $image) {
$_FILES['userfile']['name'] = $files['userfile']['name'][$key];
$_FILES['userfile']['type'] = $files['userfile']['type'][$key];
$_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][$key];
$_FILES['userfile']['error'] = $files['userfile']['error'][$key];
$_FILES['userfile']['size'] = $files['userfile']['size'][$key];
if ($this->upload->do_upload('userfile')) {
$data = $this->upload->data();
$image_data[] = $data['file_name'];
} else {
// Handle the upload error
}
}
// Save the image data to the database or do any other operation
// Redirect or show success message
}
|
1 2 3 4 |
<form method="post" action="<?= base_url('your_controller/upload_images') ?>" enctype="multipart/form-data">
<input type="file" name="userfile[]" multiple>
<button type="submit">Upload Images</button>
</form>
|
By following these steps, you can effectively use multiple images in CodeIgniter.