1

Using Codeigniter 3.1.7

Using the upload class and has allowed types set:

$config['allowed_types'] = "jpg|pdf|doc|docx|xls|xlsx|png|bmp|gif|msg|eml|zip";

Added the mime-type in config/mimes.php:

'msg' => array('text/plain','application/vnd.ms-outlook','application/octet-stream')

PHP reports the filetype I'm testing with as application/octet-stream so that should be sufficient? (IE not a duplicate of question CodeIgniter: "The filetype you are attempting to upload is not allowed." )

What might cause the error?

$this->upload->display_errors() shows:

"The filetype you are attempting to upload is not allowed."

Thanks

jtheman
  • 7,421
  • 3
  • 28
  • 39
  • did you try https://stackoverflow.com/a/10850763/5378743 ? – Roland Starke Jan 19 '18 at 14:48
  • Possible duplicate of [CodeIgniter: "The filetype you are attempting to upload is not allowed."](https://stackoverflow.com/questions/9815208/codeigniter-the-filetype-you-are-attempting-to-upload-is-not-allowed) – user2342558 Jan 19 '18 at 14:48
  • 1
    ^ No it's not a duplicate he already tried the answer, @jtherman Can you put some `var_dump()`s in the `is_allowed_filetype()`'s method? do it for the following vars: `$ext`, `$this->allowed_types`, `$this->file_type` – Spoody Jan 19 '18 at 14:50
  • i faced this error once. i just edited my allowed types set to `"*"` then everything worked well. dirty way i know. but it works! – Badiparmagi Jan 19 '18 at 14:52
  • @Badiparmagi Yes it works... then anyone can upload a PHP file and take over your server, go back and change that `*`... – Spoody Jan 19 '18 at 14:57
  • @Badiparmagi Sorry, this is a production server with sensitive data, can't allow anything, the list is already long in my opinion but I can't control that. – jtheman Jan 19 '18 at 15:03
  • @RolandStarke Yes the mime type reported by CI is `application/octet-stream` as I mentioned above, and it's included in the `/config/mimes.php` - What do you suggest me to check do you mean? – jtheman Jan 19 '18 at 15:08
  • This may not apply, but v3.1.4 fixed a bug where `get_mimes()` didn’t load `application/config/mimes.php` if an environment specific config exists. [changelog](https://www.codeigniter.com/user_guide/changelog.html#bug-fixes-for-3-1-4) – DFriend Jan 19 '18 at 15:08
  • @user2342558 No duplicate, I did check and the mime type is `application/octet-stream` – jtheman Jan 19 '18 at 15:14
  • @DFriend Thanks for the suggestion, looked promising. I tried now with system 3.1.7 in my development environment but no change... – jtheman Jan 19 '18 at 15:15
  • 1
    It is probably wise to upgrade to 3.1.7 any way. – DFriend Jan 19 '18 at 15:18
  • try to debug it... does it work with pdf, does it work if you remove pdf from `config/mimes.php`. Does it work with `'*'`.... just the see where the problem is comming from. like @Mehdi Bounya said. add some var_dumps. – Roland Starke Jan 19 '18 at 15:32
  • @RolandStarke I tried removing pdf from mimes.php and it prevented pdf from uploading. And changed to `*` in allowed_types - then I can upload msg-files as well. – jtheman Jan 19 '18 at 16:27
  • Used the CI upload example at [File Uploading Class](https://www.codeigniter.com/user_guide/libraries/file_uploading.html) and added the mime type `'msg' => 'application/vnd.ms-outlook'`. Uploading the example msg file downloaded from [HERE](https://www.online-convert.com/file-format/msg) works just fine. If I remove the mime type it fails. – DFriend Jan 19 '18 at 16:56
  • This is probably obvious but I have to ask anyway. Are you sure the case match in the file extension? Eg. not `Msg` or `MSG` instead of `msg`? – BudwiseЯ Jan 21 '18 at 01:48
  • @budwiser Yes 100% sure, it's all lowercase. But I think CI takes care of that so it doesn't matter anyway? – jtheman Jan 22 '18 at 15:38
  • @DFriend Now,this is very wierd. I can confirm the mime type are in there, I have tried both with all three types `'msg' => array('text/plain','application/vnd.ms-outlook','application/octet-stream')` and also each separate. Used both the `example.msg` file from your link and with a .msg file saved from MS Outlook directly. Reported MIME type from the $_FILES array is `application/octet-stream` but CI still say bad filetype. (updated to 3.1.7). Any more guesses? – jtheman Jan 22 '18 at 16:00
  • 1
    I'm using CI v3.1.7, PHP v7.2.1 and Apache 2.4.25 for test described above. Could be server or php version? – DFriend Jan 22 '18 at 16:18
  • One thing interesting about my test is that the payload header shows the file type as `application/octet-stream` but the test's "success page" reports the file type as 'application/vnd.ms-outlook'. – DFriend Jan 22 '18 at 16:22

1 Answers1

0

Finally this issue was solved. There was some kind of MIME-issue related to the server configuration in PHP version 7.1.14 - as soon as we updated to 7.2.x on the live server (hosting) the problem was gone. I save this answer here if it might help someone else.

jtheman
  • 7,421
  • 3
  • 28
  • 39