@domenico
To upload an image in Codeigniter, you can use the following steps:
1 2 3 4 |
<form method="post" action="upload_image" enctype="multipart/form-data"> <input type="file" name="userfile" /> <input type="submit" value="Upload Image" /> </form> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public function upload_image() { $config['upload_path'] = './uploads/'; // Set the upload path for the image $config['allowed_types'] = 'jpg|jpeg|png|gif'; // Set allowed image types $config['max_size'] = 1024; // Set max file size in KB $this->load->library('upload', $config); if (!$this->upload->do_upload('userfile')) { // Check if image is uploaded successfully $error = array('error' => $this->upload->display_errors()); print_r($error); } else { $data = array('upload_data' => $this->upload->data()); print_r($data); } } |
By following these steps, you can easily upload an image in Codeigniter.