Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
ef7d92f4
Commit
ef7d92f4
authored
Apr 14, 2014
by
Son Nguyen
Committed by
Gerrit Code Review
Apr 14, 2014
Browse files
Merge "Allowing the .zip files to be detected by file extension (Bug #1302251)"
parents
092663f9
122968dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
htdocs/lib/file.php
View file @
ef7d92f4
...
...
@@ -266,6 +266,27 @@ function byteserving_send_file($filename, $mimetype, $ranges) {
function
file_mime_type
(
$file
,
$originalfilename
=
false
)
{
static
$mimetypes
=
null
;
// Try the filename extension in case it's a file that Mahara
// cares about. For now, use the artefact_file_mime_types table,
// even though it's in a plugin and the description column doesn't
// really contain filename extensions.
if
(
$originalfilename
)
{
$basename
=
$originalfilename
;
}
else
{
$basename
=
basename
(
$file
);
}
if
(
strpos
(
$basename
,
'.'
,
1
))
{
if
(
is_null
(
$mimetypes
))
{
$mimetypes
=
get_records_assoc
(
'artefact_file_mime_types'
,
''
,
''
,
''
,
'description,mimetype'
);
}
$ext
=
strtolower
(
array_pop
(
explode
(
'.'
,
$basename
)));
if
(
isset
(
$mimetypes
[
$ext
]))
{
return
$mimetypes
[
$ext
]
->
mimetype
;
}
}
// Try detecting it with the magic.mgc file
if
(
get_config
(
'pathtomagicdb'
)
!==
null
)
{
// Manually specified magicdb path in config.php
$magicfile
=
get_config
(
'pathtomagicdb'
);
...
...
@@ -285,30 +306,10 @@ function file_mime_type($file, $originalfilename=false) {
$type
=
mime_content_type
(
$file
);
}
if
(
!
empty
(
$type
)
&&
$type
!=
'application/octet-stream'
)
{
if
(
!
empty
(
$type
))
{
return
$type
;
}
// Try the filename extension in case it's a file that Mahara
// cares about. For now, use the artefact_file_mime_types table,
// even though it's in a plugin and the description column doesn't
// really contain filename extensions.
if
(
$originalfilename
)
{
$basename
=
$originalfilename
;
}
else
{
$basename
=
basename
(
$file
);
}
if
(
strpos
(
$basename
,
'.'
,
1
))
{
if
(
is_null
(
$mimetypes
))
{
$mimetypes
=
get_records_assoc
(
'artefact_file_mime_types'
,
''
,
''
,
''
,
'description,mimetype'
);
}
$ext
=
strtolower
(
array_pop
(
explode
(
'.'
,
$basename
)));
if
(
isset
(
$mimetypes
[
$ext
]))
{
return
$mimetypes
[
$ext
]
->
mimetype
;
}
}
return
'application/octet-stream'
;
}
...
...
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