This is my front-end code:
<form action="" method="post"> <input type="file" name="image" class="input"> </form>
and controller:
$upload_image = $_FILES['image']['name']; if ($upload_image) { $config['allowed_types'] = 'xml|docx|jpg|png|pdf|xlsx'; $config['max_size'] = '999999'; $config['upload_path'] = './assets/img/image/'; $this->load->library('upload', $config); if ($this->upload->do_upload('image')) { $new_image = $this->upload->data('file_name'); $this->db->set('image', $new_image); } else { echo $this->upload->display_errors(); } }
In $config, prog knows the file type just entered, such as img docx, etc. How can I get the file type just entered as $types?
pathinfo
is an array. We can check directory name, file name, extension, etc.https://www.php.net/manual/en/function .pathinfo.php
If you're asking how to get the file type of the file you just submitted, it's easy, you just use