Browse files

avoid notice in mime()

  • Loading branch information...
1 parent dfb000f commit e1365336e20f3581a59cc9b311c686534af24fd1 @dereuromark dereuromark committed Aug 7, 2013
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/Cake/Utility/File.php
@@ -557,9 +557,14 @@ public function mime() {
if (function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME);
- list($type, $charset) = explode(';', finfo_file($finfo, $this->pwd()));
+ $finfo = finfo_file($finfo, $this->pwd());
+ if (!$finfo) {
+ return false;
+ }
+ list($type, $charset) = explode(';', $finfo);
return $type;
- } elseif (function_exists('mime_content_type')) {
+ }
+ if (function_exists('mime_content_type')) {
return mime_content_type($this->pwd());
return false;

5 comments on commit e136533

mime_content_type() has been marked deprecated for a long time (at least 2009), maybe the fallback should be removed? finfo Should be installed by default (

For CakePHP 3;
PHP 5.3+ has an additional constant FILEINFO_MIME_TYPE that returns the mime-type without the charset; No need to explode()

p.s. Please don't see my comments as critique; I'm planning on starting pull-requests in the near future; haven't found the time to do so yet :)


ADmad replied Aug 15, 2013

@thaJeztah fileinfo is installed by default for php 5.3+. CakePHP still supports php 5.2 ;)
Feel free to provide a patch with for CakePHP 3 though.

@ADmad you're right, I missed the version. Will try to start contributing soon, currently getting familiar with GIT (coming from SVN) and get my Unit-tests to work properly to see if I don't break anything :D

Off-topic, but I noticed some things still in 3.0 that are marked to be removed in 3; Should I create pull requests for those, or would that make it more difficult to keep the 3.0 branch up-to-date with changes from the 2.x branch?


markstory replied Aug 16, 2013

They've not been removed because it makes merging harder. Removing them will happen well before the RC/stable release though. In the past the -dev and -alpha releases keep error/exception throwing methods to help early adopters upgrade.

@markstory clear (I, kind of, expected that). Throwing Exceptions seems like a good solution; A 'special' type of exception or logging mechanism might be nice; approaching it like the jQuery Migration plugin. I'll let my mind wander

Thanks for your time!

Please sign in to comment.