Commit dbc671a6 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Use mime_content_type when the browser serves leap2a zip file as application/octet-stream


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent a6475339
...@@ -199,10 +199,18 @@ function adduser_validate(Pieform $form, $values) { ...@@ -199,10 +199,18 @@ function adduser_validate(Pieform $form, $values) {
$form->set_error('leap2afile', get_string('failedtoobtainuploadedleapfile', 'admin')); $form->set_error('leap2afile', get_string('failedtoobtainuploadedleapfile', 'admin'));
} }
if ($values['leap2afile']['type'] == 'application/octet-stream') {
// the browser wasn't sure, so use mime_content_type to guess
$mimetype = mime_content_type($filename);
}
else {
$mimetype = $values['leap2afile']['type'];
}
safe_require('artefact', 'file'); safe_require('artefact', 'file');
$ziptypes = PluginArtefactFile::get_mimetypes_from_description('zip'); $ziptypes = PluginArtefactFile::get_mimetypes_from_description('zip');
if (in_array($values['leap2afile']['type'], $ziptypes)) { if (in_array($mimetype, $ziptypes)) {
// Unzip the file // Unzip the file
$command = sprintf('%s %s %s %s', $command = sprintf('%s %s %s %s',
escapeshellcmd(get_config('pathtounzip')), escapeshellcmd(get_config('pathtounzip')),
...@@ -230,7 +238,7 @@ function adduser_validate(Pieform $form, $values) { ...@@ -230,7 +238,7 @@ function adduser_validate(Pieform $form, $values) {
} }
} }
else if ($values['leap2afile']['type'] != 'text/xml') { else if ($mimetype != 'text/xml') {
$form->set_error('leap2afile', get_string('fileisnotaziporxmlfile', 'admin')); $form->set_error('leap2afile', get_string('fileisnotaziporxmlfile', 'admin'));
} }
$LEAP2A_FILE = $filename; $LEAP2A_FILE = $filename;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment