这是我的前端代码:
<form action="" method="post"> <input type="file" name="image" class="input"> </form>
和控制器:
$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(); } }
在 $config 中,prog 知道刚刚输入的文件类型,例如 img docx 等,我如何获取刚刚作为 $types 输入的文件类型?
P粉7864325792024-03-23 09:14:05
pathinfo
是一个数组。我们可以检查目录名称、文件名、扩展名等。
$path_parts = pathinfo('test.png'); echo $path_parts['extension'], "\n"; echo $path_parts['dirname'], "\n"; echo $path_parts['basename'], "\n"; echo $path_parts['filename'], "\n";
https://www.php.net/manual/en/function .pathinfo.php