I'm using Uploadify and Kohana and I'm creating file uploader. User can upload only few types of files.
Kohana have great library of MIME types built-in. I thought that it would be cool to check that MIME type of uploaded file (it came from Uploadify) match setted file extensions. That's why I made an array of allowed MIME types.
$mimes = (array) Kohana::config('mimes');
$allowed_mimes = array_merge($mimes['bmp'], $mimes['gif'], $mimes['jpg'], $mimes['jpeg'], $mimes['png']);
Next, I wanted to check that uploaded files MIME type is in $allowed_mimes
array. I used something like in_array($file['type'], $allowed_mimes)
. For surprise to me - actual MIME of file was application/octet-stream
. Anyway, uploaded file was JPEG
image. How this is possible?
Basic idea is that I need to check file type. What's the best way to do it?
Edit:
After some conversions with my colleagues, I decided to check chars after last dot. Like virus.jpeg
is acceptable, because of jpeg
is in its name. i'm still open for better solutions!
$extension = ltrim(strrchr($file['name'], '.'), '.')