Browse Source

Merge pull request #3804 from Ragazzo/fileinfo_added_to_requirements_checks

fileinfo check
tags/2.0.0-rc
Qiang Xue 10 years ago
parent
commit
e48ff22222
  1. 3
      framework/UPGRADE.md
  2. 4
      framework/helpers/BaseFileHelper.php
  3. 7
      framework/requirements/requirements.php

3
framework/UPGRADE.md

@ -47,3 +47,6 @@ Upgrade from Yii 2.0 Beta
* The database table of the `yii\log\DbTarget` now needs a `prefix` column to store context information.
You can add it with `ALTER TABLE log ADD COLUMN prefix TEXT AFTER log_time;`.
* The `fileinfo` PHP extension is now required by Yii. If you use `yii\helpers\FileHelper::getMimeType()`, make sure
you have enabled this extension. This extension is [builtin](http://www.php.net/manual/en/fileinfo.installation.php) in php above `5.3`.

4
framework/helpers/BaseFileHelper.php

@ -120,16 +120,16 @@ class BaseFileHelper
*/
public static function getMimeType($file, $magicFile = null, $checkExtension = true)
{
if (function_exists('finfo_open')) {
$info = finfo_open(FILEINFO_MIME_TYPE, $magicFile);
if ($info) {
$result = finfo_file($info, $file);
finfo_close($info);
if ($result !== false) {
return $result;
}
}
}
return $checkExtension ? static::getMimeTypeByExtension($file) : null;
}

7
framework/requirements/requirements.php

@ -47,4 +47,11 @@ return array(
in <code>Yii::t()</code>, <abbr title="Internationalized domain names">IDN</abbr>-feature of
<code>EmailValidator</code> or <code>UrlValidator</code> or the <code>yii\i18n\Formatter</code> class.'
),
array(
'name' => 'Fileinfo extension',
'mandatory' => true,
'condition' => extension_loaded('fileinfo'),
'by' => '<a href="http://www.php.net/manual/en/book.fileinfo.php">File Information</a>',
'memo' => 'Required for files upload to detect correct file mime-types.'
),
);

Loading…
Cancel
Save