Uploading zip and rar file not working in codeigniter

纵然是瞬间 提交于 2019-12-30 11:29:33

问题


setting i have created for allowed type:

  $config['allowed_types'] = 'doc|docx|pdf|xls|xlsx|rtf|txt|rar|zip';

and in my 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'),

this is all i have configured but when i do the zip or rar upload its shows me error that "The filetype you are attempting to upload is not allowed."

PLEASE HELP ANY ONE .. THANKS IN ADVANCE..


回答1:


i replace the mime.php configuration for zip and rar to:

 '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'),

i have just added the application/octet-stream at the end.. for both the type and now i am able to upload both zip and rar... :) now i am happy




回答2:


Here is the best way to check MIME type.

open system/libraries/upload.php in codeigniter framework. Check the commented below. You will get the exact MIME type and include the same MIME type in your mimes.php file.

// 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;
        }


来源:https://stackoverflow.com/questions/20300354/uploading-zip-and-rar-file-not-working-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!