Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
74843ccb
Commit
74843ccb
authored
Jun 30, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make fileinfo optional requirement
parent
08b7636d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
1 deletion
+10
-1
BaseFileHelper.php
framework/helpers/BaseFileHelper.php
+10
-1
No files found.
framework/helpers/BaseFileHelper.php
View file @
74843ccb
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
yii\helpers
;
namespace
yii\helpers
;
use
Yii
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidParamException
;
use
yii\base\InvalidParamException
;
/**
/**
...
@@ -117,9 +118,17 @@ class BaseFileHelper
...
@@ -117,9 +118,17 @@ class BaseFileHelper
* @param boolean $checkExtension whether to use the file extension to determine the MIME type in case
* @param boolean $checkExtension whether to use the file extension to determine the MIME type in case
* `finfo_open()` cannot determine it.
* `finfo_open()` cannot determine it.
* @return string the MIME type (e.g. `text/plain`). Null is returned if the MIME type cannot be determined.
* @return string the MIME type (e.g. `text/plain`). Null is returned if the MIME type cannot be determined.
* @throws InvalidConfigException when the `fileinfo` PHP extension is not installed and `$checkExtension` is `false`.
*/
*/
public
static
function
getMimeType
(
$file
,
$magicFile
=
null
,
$checkExtension
=
true
)
public
static
function
getMimeType
(
$file
,
$magicFile
=
null
,
$checkExtension
=
true
)
{
{
if
(
!
extension_loaded
(
'fileinfo'
))
{
if
(
$checkExtension
)
{
return
static
::
getMimeTypeByExtension
(
$file
,
$magicFile
);
}
else
{
throw
new
InvalidConfigException
(
'The fileinfo PHP extension is not installed.'
);
}
}
$info
=
finfo_open
(
FILEINFO_MIME_TYPE
,
$magicFile
);
$info
=
finfo_open
(
FILEINFO_MIME_TYPE
,
$magicFile
);
if
(
$info
)
{
if
(
$info
)
{
...
@@ -131,7 +140,7 @@ class BaseFileHelper
...
@@ -131,7 +140,7 @@ class BaseFileHelper
}
}
}
}
return
$checkExtension
?
static
::
getMimeTypeByExtension
(
$file
)
:
null
;
return
$checkExtension
?
static
::
getMimeTypeByExtension
(
$file
,
$magicFile
)
:
null
;
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment