Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
122fa190
Commit
122fa190
authored
13 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
improve mimetype detection
parent
38bb503f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/filestorage/local.php
+12
-9
12 additions, 9 deletions
lib/filestorage/local.php
with
12 additions
and
9 deletions
lib/filestorage/local.php
+
12
−
9
View file @
122fa190
...
...
@@ -126,18 +126,21 @@ class OC_Filestorage_Local extends OC_Filestorage{
public
function
getMimeType
(
$fspath
){
if
(
$this
->
is_readable
(
$fspath
)){
$mimeType
=
'application/octet-stream'
;
if
(
@
is_dir
(
$this
->
datadir
.
$fspath
))
{
// directories are easy
return
"httpd/unix-directory"
;
}
elseif
(
function_exists
(
'finfo_open'
)
and
function_exists
(
'finfo_file'
)
and
$finfo
=
finfo_open
(
FILEINFO_MIME
)){
}
if
(
$mimeType
==
'application/octet-stream'
and
function_exists
(
'finfo_open'
)
and
function_exists
(
'finfo_file'
)
and
$finfo
=
finfo_open
(
FILEINFO_MIME
)){
$mimeType
=
strtolower
(
finfo_file
(
$finfo
,
$this
->
datadir
.
$fspath
));
$mimeType
=
substr
(
$mimeType
,
0
,
strpos
(
$mimeType
,
';'
));
finfo_close
(
$finfo
);
return
$mimeType
;
}
else
if
(
function_exists
(
"mime_content_type"
))
{
}
if
(
$mimeType
==
'application/octet-stream'
&&
function_exists
(
"mime_content_type"
))
{
// use mime magic extension if available
$mime_type
=
mime_content_type
(
$this
->
datadir
.
$fspath
);
}
else
if
(
OC_Helper
::
canExecute
(
"file"
))
{
$mimeType
=
mime_content_type
(
$this
->
datadir
.
$fspath
);
}
if
(
$mimeType
==
'application/octet-stream'
&&
OC_Helper
::
canExecute
(
"file"
))
{
// it looks like we have a 'file' command,
// lets see it it does have mime support
$fspath
=
str_replace
(
"'"
,
"\'"
,
$fspath
);
...
...
@@ -146,18 +149,18 @@ class OC_Filestorage_Local extends OC_Filestorage{
pclose
(
$fp
);
//trim the character set from the end of the response
$mime
_t
ype
=
substr
(
$reply
,
0
,
strrpos
(
$reply
,
' '
));
$mime
T
ype
=
substr
(
$reply
,
0
,
strrpos
(
$reply
,
' '
));
}
if
(
empty
(
$mime
_t
ype
)
)
{
if
(
$mime
T
ype
==
'application/octet-stream'
)
{
// Fallback solution: (try to guess the type by the file extension
if
(
!
self
::
$mimetypes
){
self
::
$mimetypes
=
include
(
'mimetypes.list.php'
);
}
$extention
=
strtolower
(
strrchr
(
basename
(
$fspath
),
"."
));
$extention
=
substr
(
$extention
,
1
);
//remove leading .
$mime
_t
ype
=
(
isset
(
self
::
$mimetypes
[
$extention
]))
?
self
::
$mimetypes
[
$extention
]
:
'application/octet-stream'
;
$mime
T
ype
=
(
isset
(
self
::
$mimetypes
[
$extention
]))
?
self
::
$mimetypes
[
$extention
]
:
'application/octet-stream'
;
}
return
$mime
_t
ype
;
return
$mime
T
ype
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment