Heim > Fragen und Antworten > Hauptteil
Das ist mein Frontend-Code:
<form action="" method="post"> <input type="file" name="image" class="input"> </form>
und 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 kennt prog den gerade eingegebenen Dateityp, z. B. img docx usw. Wie kann ich den gerade eingegebenen Dateityp als $types erhalten?
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