Fix file upload when multiple files are selected at once

merge-requests/18/head
Mike Koch 8 years ago
parent 4a86d9ddbb
commit dd5c5a90d3

@ -41,14 +41,16 @@ function hesk_uploadFile($i, $isTicket = true)
global $hesk_settings, $hesklang, $trackingID, $hesk_error_buffer, $modsForHesk_settings;
/* Return if name is empty */
$name = $_FILES['attachment']['name'][$i];
$name = $i == -1
? $_FILES['attachment']['name']
: $_FILES['attachment']['name'][$i];
if (empty($name)) {
return '';
}
/* Parse the name */
$file_realname = hesk_cleanFileName($_FILES['attachment']['name'][$i]);
$file_realname = hesk_cleanFileName($name);
/* Check file extension */
$ext = strtolower(strrchr($file_realname, "."));
@ -57,7 +59,9 @@ function hesk_uploadFile($i, $isTicket = true)
}
/* Check file size */
$size = $_FILES['attachment']['size'][$i];
$size = $i == -1
? $_FILES['attachment']['size']
: $_FILES['attachment']['size'][$i];
if ($size > $hesk_settings['attachments']['max_size']) {
return hesk_fileError(sprintf($hesklang['file_too_large'], $file_realname));
} else {
@ -88,7 +92,9 @@ function hesk_uploadFile($i, $isTicket = true)
if (!$isTicket) {
$directory = $modsForHesk_settings['kb_attach_dir'];
}
$file_to_move = $_FILES['attachment']['tmp_name'][$i];
$file_to_move = $i == -1
? $_FILES['attachment']['tmp_name']
: $_FILES['attachment']['tmp_name'][$i];
if (!move_uploaded_file($file_to_move, dirname(dirname(__FILE__)) . '/' . $directory . '/' . $file_name)) {
return hesk_fileError($hesklang['cannot_move_tmp']);
}

@ -298,7 +298,8 @@ function display_dropzone_field($url, $id = 'filedrop') {
dictCancelUploadConfirmation: ".json_encode($hesklang['attachment_confirm_cancel']).",
dictRemoveFile: ".json_encode($hesklang['attachment_remove']).",
previewTemplate: $('#previews').html(),
clickable: '.filedropbutton-".$id."'
clickable: '.filedropbutton-".$id."',
uploadMultiple: false
};
</script>
";

@ -16,7 +16,7 @@ $modsForHesk_settings = mfh_getSettings();
if (!empty($_FILES)) {
// Only 1 files is ever processed through this endpoint at a time.
$id = upload_temp_attachment(0, false);
$id = upload_temp_attachment(-1, false);
print json_encode($id);
return http_response_code(200);
}

@ -15,8 +15,7 @@ hesk_dbConnect();
$modsForHesk_settings = mfh_getSettings();
if (!empty($_FILES)) {
// Only 1 files is ever processed through this endpoint at a time.
$id = upload_temp_attachment(0, true);
$id = upload_temp_attachment(-1, true);
print json_encode($id);
return http_response_code(200);
}

Loading…
Cancel
Save