限制用户只能上传指定的文件格式

Limit users to upload only the specified file formats

本文关键字:文件 格式 用户      更新时间:2023-09-26

我设法让用户上传pdf,doc和docx格式的文件。但是,用户现在可以上传任何格式的文件。这并不能阻止他们。他们可以上传任何格式的文件,但程序不会将它们存储在上传路径中。我想严格要求他们只上传我的格式,如果格式不同,程序会阻止他们。我把我的代码作为额外的参考:

 $config['upload_path'] = './media/resumes/';

  $config['allowed_types'] = 'pdf|doc|docx';
    $config['max_size'] = '100000';
        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        $this->upload->do_upload("myfile");           
        $file = $this->upload->data();
            $filename=$file['file_name'];

期待您的回答

您可以在附加文件时使用:

        <input type="file" name="userfile" id="fileAttachmentID" accept=".pdf,.doc,.docx">