CodeIgniter: “The filetype you are attempting to upload is not allowed.”

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 14:44:16
Rocco

You are using Firefox, aren't you?

You could try looking at system/libraries/Upload.php line 199:

$this->_file_mime_type($_FILES[$field]);

Change that line to:

$this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die();

Then do upload your .wmv file. It would show something like application/octet-stream or whatever. Add that to your mimes.php. Hope this help =)

Similar answer here

Some links:

$config["allowed_types"] ="*";

  1. Upload your .wmv file to the server using FTP/SFTP/scp/etc where you run the CodeIgniter application
  2. On the server where you have uploaded the .wmv file, execute the following PHP code

    <?php
    $file_path = 'CHANGE_THIS_TO_ABSOLUTE_FILE_PATH_THAT_YOU_HAVE_UPLOADED.wmv';
    $finfo = finfo_open(FILEINFO_MIME);
    $mime = finfo_file($finfo, $file_path);
    var_dump($mime);
    ?>
    
  3. Save the code as mime.php

  4. Run in the terminal - $ php mime.php
  5. If it dumps any other value than you already have for wmv, append that value into wmv mime types.

Also check PHP_VERSION in other development machines. finfo_open is introduced in PHP 5.3. The development machine where upload is working may have an older version of PHP or it may have right mime type for the wmv.

did you try using mime types instead of extensions in $config['allowed_types']?

write it like this

$config["allowed_types"] = "video/x-msvideo|image/jpeg|video/mpeg|video/x-ms-wmv";

I've recently had some very similar problems with the Codeigniter's Upload Class.

The *allowed_types* doesn't seem to be working. For example, I wanted to allow .PNG images to be uploaded, but it wouldn't allow them through it's filter. I ended up investigating it further. I allowed all file types to be temporarily uploaded, I uploaded a .PNG, and then dumped the upload data ($this->upload->data());). For some reason, it thought the MIME type was text/plain! This might be related to your problem.

There are some solutions to this I found surfing some forums where you can modify/extend the class or core, but they didn't work for me -- sorry. I believe it's a Codeigniter Core bug (I think the issue has already been opened with EllisLabs). I ended up hard-coding the damn thing anyways! Well, I hope this helps you some.

Basic example/work-around,

//replace with your allowed MIME types
if ($_FILES['name_of_form_upload']['type'] != 'image/jpeg' && $_FILES['name_of_form_upload']['type'] != 'image/png' && $_FILES['name_of_form_upload']['type'] != 'image/gif') {
    $data['message'] = '<div class="message">That file type is not allowed!</div>';
    $this->load->view('home_view', $data);
} else {
    //run upload code
}

Edit: Formatting/Grammar

Anil

Answer for to Upload .doc file in CodeIgniter

Change this

'doc'   =>  'application/msword',

With this on line no 95 (application/config/mimes.php file)

'doc'   =>  array('application/vnd.ms-word','application/msword'),

Check your mimes.php file in application/config. It should return an array of mime types e.g return $mimes; at end of file or return array(..... in start of mimes array.

This is actually a bug in the core.. I upgraded to latest version of CI and the bug disappeared.

if you need the simple way to solve this,there is an easy solution for it. open "system/libraries/Upload.php" file

line no 465
you will see 
if ( ! $this->is_allowed_filetype())
        {
            $this->set_error('upload_invalid_filetype', 'debug');
            return FALSE;
        }


just make it true

    if ( ! $this->is_allowed_filetype())
            {
                $this->set_error('upload_invalid_filetype', 'debug');
                return TRUE;
            }

note : it will stop your all file type validation.

Change IN application\config\Mimes.php

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