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

后端 未结 7 478
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 21:04

I was searching a lot and found many questions regarding this problem, unfortunately none of answers did help me.

I\'m trying to upload a png image, and I\'m receivi

相关标签:
7条回答
  • 2020-12-20 21:25

    Add ‘text/plain’ to the CSV array in config/mimes.php to $mimes arrays

    0 讨论(0)
  • 2020-12-20 21:25
    $this->load->library('upload');  
    
    $this->upload->set_allowed_types('*'); 
    
    
    class MY_Upload extends CI_Upload {  
    
        function is_allowed_filetype() {  
    
            if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))  
            {  
                $this->set_error('upload_no_file_types');  
                return FALSE;  
            }  
    
            if (in_array("*", $this->allowed_types))  
            {  
                return TRUE;  
            }  
    
            $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');  
    
            foreach ($this->allowed_types as $val)  
            {  
                $mime = $this->mimes_types(strtolower($val));  
    
                // Images get some additional checks  
                if (in_array($val, $image_types))  
                {  
                    if (getimagesize($this->file_temp) === FALSE)  
                    {  
                        return FALSE;  
                    }  
                }  
    
                if (is_array($mime))  
                {  
                    if (in_array($this->file_type, $mime, TRUE))  
                    {  
                        return TRUE;  
                    }  
                }  
                else  
                {  
                    if ($mime == $this->file_type)  
                    {  
                        return TRUE;  
                    }  
                }  
            }  
    
            return FALSE;  
    
        }  
    
    }  
    
    0 讨论(0)
  • 2020-12-20 21:31

    another solution is to enable extension=php_fileinfo.dll in php.ini

    0 讨论(0)
  • 2020-12-20 21:37

    i just add this line in mime.php on line 34 and pptx is now uploading. test it on real server

    'pptx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),

    0 讨论(0)
  • 2020-12-20 21:45

    Replacing the codeigniter 2.1.0 system/libraries/upload.php with 2.1.2 version upload.php library solves the problem. Hope this helps

    0 讨论(0)
  • 2020-12-20 21:45

    Actually, in my case, I created a blob object from a canvas by void canvas.toBlob(callback, mimeType, qualityArgument) method So the blob file does NOT have its real name (which has an extension), it's just only 'blob'. So I have to use the legacy way to upload the file, instead of an 'upload' library:

    move_uploaded_file ( $file["tmp_name"], $target_file )
    
    0 讨论(0)
提交回复
热议问题