Uploading zip and rar file not working in codeigni

2020-03-29 05:26发布

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..

2条回答
劳资没心,怎么记你
2楼-- · 2020-03-29 05:28

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

查看更多
萌系小妹纸
3楼-- · 2020-03-29 05:32

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;
        }
查看更多
登录 后发表回答