设置我已为允许的类型创建:
$config['allowed_types'] = 'doc|docx|pdf|xls|xlsx|rtf|txt|rar|zip';
和我的mine.php
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed','application/force-download'),
'rar' => array('application/x-rar', 'application/rar','application/x-rar-compressed','application/force-download'),
这是我已经配置的所有内容,但是当我执行zip或rar上传时,它会显示错误“您尝试上传的文件类型是不允许的。”
请帮助任何一个......感谢提前......
答案 0 :(得分:10)
我将zip和rar的mime.php配置替换为:
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed','application/force-download','application/octet-stream'),
'rar' => array('application/x-rar', 'application/rar','application/x-rar-compressed','application/force-download','application/octet-stream'),
我刚刚在最后添加了应用程序/八位字节流..对于这两种类型,现在我可以上传zip和rar ... :)现在我很高兴
答案 1 :(得分:1)
这是检查MIME类型的最佳方法。
在codeigniter框架中打开system / libraries / upload.php。检查下面的评论。您将获得确切的MIME类型,并在mimes.php文件中包含相同的MIME类型。
// Set the uploaded data as class variables
$this->file_temp = $_FILES[$field]['tmp_name'];
$this->file_size = $_FILES[$field]['size'];
$this->_file_mime_type($_FILES[$field]);
$this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $this->file_type);
$this->file_type = strtolower(trim(stripslashes($this->file_type), '"'));
$this->file_name = $this->_prep_filename($_FILES[$field]['name']);
$this->file_ext = $this->get_extension($this->file_name);
$this->client_name = $this->file_name;
//var_dump($this->file_type); Added by pratikn to check mime type
//exit();
// Is the file type allowed to be uploaded?
if (!$this->is_allowed_filetype()) {
$this->set_error('upload_invalid_filetype');
return FALSE;
}