We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Upload library returning incorrect mime type for .csv files

Development and Programming

David Hyland's avatar
David Hyland
210 posts
14 years ago
David Hyland's avatar David Hyland

I’m trying to create a custom file upload (using CI’s upload class) but when uploading a CSV file the file type is being set as “text/html” and therefore fails the mime type checks. All other file types I’ve tested are uploaded correctly. I even have XSS filtering set to Off.

Any ideas what’s going on here?

EE 2.2.1

       
Shane Eckert's avatar
Shane Eckert
7,174 posts
14 years ago
Shane Eckert's avatar Shane Eckert

Hello David,

I am sorry to hear you are running into this snag.

Can you check your system/expressionengine/config/mimes.php file for the CSV file type? If it is not yet defined, adding it there should help. If it is in there, make sure that for some reason it was not set incorrectly.

Please let me know if this helps.

Cheers,

       
David Hyland's avatar
David Hyland
210 posts
14 years ago
David Hyland's avatar David Hyland

Hi Shane

Yes, it’s there. Here’s what I’ve got:

'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),

Looks good to me. What else can I try?

       
Dan Decker's avatar
Dan Decker
7,338 posts
14 years ago
Dan Decker's avatar Dan Decker

Hi David,

From the looks of it, it seems your developing an add-on?

Can you give me a little more insight into what your goal is? Where is the provided file field type falling short for you?

If you can explain to me what your desired end result is, I’m happy to offer suggestions. However, if you are needing help with add-on development, I’ll have to move this into Development and Programming.

I look forward to your reply!

Cheers,

       
David Hyland's avatar
David Hyland
210 posts
14 years ago
David Hyland's avatar David Hyland

Hi Dan

Yes, it’s a custom module and one of the methods is to import a CSV file into a custom db table using CI’s Upload class. However on uploading the .csv file, with the ‘allowed_types’ parameter set to “csv|xls|xlsx”, the $_FILES[‘type’] global var has the type set as ‘text/html’, therefore fails the file type test.

I realise this sounds like it could be a browser issue but the upload function used to work just fine on the same site a few months back before I upgraded EE from 2.1.4 to 2.2.1

With allowed_types set as “*” the upload works fine. So maybe it’s a CodeIgniter issue.

Okay, so ye, please nudge this over to whichever forum you deem appropriate.

Cheers

David

       
Dan Decker's avatar
Dan Decker
7,338 posts
14 years ago
Dan Decker's avatar Dan Decker

Hi David,

One quick question here, are you using the upload class as through the EE super object or at the model level where it’s is directly called by CI?

I’ll get this over to Development and Programming. The Community there is far more versed in these issues that we are!

Cheers,

       
David Hyland's avatar
David Hyland
210 posts
14 years ago
David Hyland's avatar David Hyland

Hey Dan, I’m using CI’s object:

$this->CI =& get_instance();
$config['allowed_types'] = 'csv|xls|xlsx';
$this->CI->load->library('upload', $config);
if ($this->CI->upload->do_upload())
{
...
}
       
pminetti's avatar
pminetti
1 posts
12 years ago
pminetti's avatar pminetti

Hi, I have the same problem, debugging CI code find two possible solutions

1 - add the mime type to the file mimes.php as is mentioned before 2 - in the upload class in method do_upload at line 207 ci call the private method is_allowed_filetype(), that’s make the method set by default ignore_mime as FALSE, if you call the method like is_allowed_filetype(TRUE) this solve the problem because methon don’t do any check of mime type. But… as you can see you have to modify CI code because there is not way by parameter to change how you call the method.

Perhaps in the future someone correct this problem. sorry for may bad english. 😉

       
OtiliaBecker's avatar
OtiliaBecker
4 posts
2 months ago
OtiliaBecker's avatar OtiliaBecker

I successfully fixed that error, thank you. Edit by grow a garden a day ago

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.