0

I'm creating an upload form using CodeIgniter and I'm uploading a file with a .apk extension. in My controller for time I have used * which is working but I want to allow the only apk files.

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

can anyone help me to create custom mime type with sample code.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Noob
  • 29
  • 9

3 Answers3

1

I hope it's not too late to answer this question!!

I was implementing a similar thing and ran into the same issue! After a bit of research on stackoverflow, I have a tried and tested answer.

As @phobia82 correctly said, this is an issue of mime types. Having checked in some browsers and CodeIgniter 3.x, adding a custom mime type is what helps! Also, worth noting is the fact that apk files are recognized with 2 mime types (from what I have tested)

| application/vnd.android.package-archive |
|-----------------------------------------|
| application/java-archive                |

So, goto config/mimes.php and add this to the array

'apk'   =>  array('application/vnd.android.package-archive','application/java-archive')

This was the reason why my upload failed. Codeigniter detected the APK archive as a java archive and the Apache server detected this as vnd.android.package-archive. Once you are done with this, you can use

$config['allowed_types'] = 'apk';

Hope this helps!!

Arcanyx
  • 852
  • 10
  • 25
0

In the docs, allowed_types refers to

The mime types corresponding to the types of files you allow to be uploaded. Usually the file extension can be used as the mime type. Can be either an array or a pipe-separated string.

So you can use:

$config['allowed_types'] = 'apk';

If you want to be more specific and check the actual MIME type, for apk this is

application/vnd.android.package-archive
phobia82
  • 1,257
  • 8
  • 10
-1
$config['allowed_types'] = 'apk';

You can use this.

It will work fine.

thank you.

Abdul Hameed
  • 263
  • 4
  • 19
  • it won't work I have tried this it gives me an error "The filetype you are attempting to upload is not allowed." – Noob Dec 08 '16 at 08:10
  • then u can use javascript validation for that – Abdul Hameed Dec 08 '16 at 10:28
  • This will not work if there is "apk" array in the core mlmes.php file, which there isn't. Suggesting javascript is not a good idea. – stef Jan 22 '17 at 13:00