How to get data type from input php file
P粉670107661
P粉670107661 2024-03-22 10:41:04
0
2
269

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?

P粉670107661
P粉670107661

reply all(2)
P粉786432579

pathinfo is an array. We can check directory name, file name, extension, etc.

$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

P粉438918323

If you're asking how to get the file type of the file you just submitted, it's easy, you just use

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!