fix #15; mime type validation when uploading file

parent e5a7c0d5
......@@ -66,7 +66,23 @@ class Lab
'randomize' => true,
]));
$attachment->getValidatorChain()
->attach(new Validator\File\UploadFile());
->attach(new Validator\File\UploadFile())
->attach(new Validator\File\MimeType([
'application/zip',
'application/x-rar-compressed',
'application/octet-stream',
'application/pdf',
'image/png',
'image/jpeg',
'image/gif',
'image/bmp',
'image/vnd.microsoft.icon',
'image/tiff',
'image/tiff',
'image/svg+xml',
'image/svg+xml',
'image/vnd.adobe.photoshop',
]));
$use_ext_program= new Input('use_ext_program');
$use_ext_program->setRequired(false);
......
......@@ -142,7 +142,9 @@ class LabService implements LabServiceInterface
mkdir($fullPath, 0700, true);
}
// remove previous
unlink($this->filesPath . '/' . $lab->attachment);
if ($lab->attachment) {
unlink($this->filesPath . '/' . $lab->attachment);
}
// move new file
rename($attachment['tmp_name'], $fullPath . '/' . $attachment['name']);
$lab->attachment = $schoolPath . '/' . $attachment['name'];
......
......@@ -23,15 +23,21 @@
render: function (form, messages) {
var renderMessages = function (element, messages) {
var key,
ul;
ul,
inputGrp;
element.parents('.form-group').addClass('has-error');
inputGrp = element.parents('.input-group');
ul = $('<ul class="help-block has-error">');
for (key in messages) {
if (messages.hasOwnProperty(key)) {
ul.append($('<li>').text(messages[key]));
}
}
element.after(ul);
if (inputGrp.length > 0) {
inputGrp.after(ul);
} else {
element.after(ul);
}
};
var prop;
this.clear(form);
......
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