Codeigniter : The filetype you are attempting to upload is not allowed. Yesterday it was fine

前端 未结 5 1430
忘了有多久
忘了有多久 2021-01-25 23:45

My codeigniter app suddenly broke today. I didn\'t work on the upload code and when I tried to upload an image today I suddenly got \"The filetype you are attempting to upload i

相关标签:
5条回答
  • 2021-01-25 23:57

    I've had this problem twice, here are the two solutions that have worked for me;

    1 - The mime type reported by the system can vary, and may not be in the array of mime types set for a particular file extension. .csv files are the worst I have found for this. Find out what mime type the system is reporting by dumping the upload data after your upload

    die($this->upload->data());
    

    The 'file_type' index will contain a string - add this to the array value with the index that matches the desired file extension in application/config/mimes.php

    2 - The most recent time I have had this is when I upgraded my core Codeiginter version from 2.x to 3.x. I updated the contents of the system directory, but not application/config. I didn't spot the fact that the application/config/mimes.php file is slightly different - the newer version returns an array whereas the old one included it as a var. The fix was to copy in the newer version of mimes.php

    0 讨论(0)
  • 2021-01-26 00:00

    Have you initialize the $config properly?

    $this->load->library('upload', $config);
    $this->upload->initialize($config); // Make sure it has been initialized
    
    0 讨论(0)
  • 2021-01-26 00:10

    Not sure if this helps, I had this problem only on my Windows Dev Machine running on a test server on local host, on my live web hosting it worked fine detecting mime types.

    I had a quick look at the upload library itself, and I found that you can just stick a * in the allowed types to allow anything.

    Don't think this was documented anywhere in the manual, but sorted the problem for me as I just wanted to get my script up and running locally to do some work on it.

    0 讨论(0)
  • 2021-01-26 00:18

    Initialize $config and remove base_url() from upload path. It will work properly.

    $this->upload->initialize($config);
    
    0 讨论(0)
  • 2021-01-26 00:20

    I had the same problem today.

    What I did is just to copy the whole content of CodeIgniter-3.0.6\application\config\mimes.php to my application\config\mimes.php.

    0 讨论(0)
提交回复
热议问题