mirror of https://github.com/itflow-org/itflow
Feature: You can now upload multiple files at a time in the client files section
This commit is contained in:
parent
8f9753489f
commit
44c4beba1e
|
|
@ -14,7 +14,7 @@ $num_of_files = mysqli_num_rows($sql_files_images) + mysqli_num_rows($sql_files_
|
|||
<div class="card-header py-2">
|
||||
<h3 class="card-title mt-2"><i class="fa fa-fw fa-paperclip mr-2"></i>Files</h3>
|
||||
<div class="card-tools">
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addFileModal"><i class="fas fa-fw fa-cloud-upload-alt mr-2"></i>Upload File</button>
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addFilesModal"><i class="fas fa-fw fa-cloud-upload-alt mr-2"></i>Upload File</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
|
@ -108,7 +108,7 @@ $num_of_files = mysqli_num_rows($sql_files_images) + mysqli_num_rows($sql_files_
|
|||
</div>
|
||||
|
||||
<?php
|
||||
require_once("client_file_add_modal.php");
|
||||
require_once("client_files_add_modal.php");
|
||||
require_once("share_modal.php");
|
||||
require_once("client_file_delete_modal.php");
|
||||
require_once("footer.php");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
<div class="modal" id="addFilesModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-cloud-upload-alt mr-2"></i>Upload Files</h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
<div class="form-group">
|
||||
<input type="file" class="form-control-file" name="file[]" multiple accept=".jpg, .jpeg, .gif, .png, .webp, .pdf, .txt, .md, .doc, .docx, .odt, .csv, .xls, .xlsx, .ods, .pptx, .odp, .zip, .tar, .gz, .xml, .msg, .json, .wav, .mp3, .ogg, .mov, .mp4, .av1">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="submit" name="add_files" class="btn btn-primary text-bold"><i class="fa fa-upload mr-2"></i>Upload</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -4,28 +4,30 @@
|
|||
* ITFlow - GET/POST request handler for client files/uploads
|
||||
*/
|
||||
|
||||
if (isset($_POST['add_file'])) {
|
||||
if (isset($_POST['add_files'])) {
|
||||
$client_id = intval($_POST['client_id']);
|
||||
$file_name = sanitizeInput($_POST['new_name']);
|
||||
|
||||
$extarr = explode('.', $_FILES['file']['name']);
|
||||
$file_extension = sanitizeInput(strtolower(end($extarr)));
|
||||
|
||||
// If the user-inputted name is empty, revert to the name of the file on disk/uploaded
|
||||
if (empty($file_name)) {
|
||||
$file_name = sanitizeInput($_FILES['file']['name']);
|
||||
}
|
||||
|
||||
|
||||
if (!file_exists("uploads/clients/$client_id")) {
|
||||
mkdir("uploads/clients/$client_id");
|
||||
}
|
||||
|
||||
//Check to see if a file is attached
|
||||
if ($_FILES['file']['tmp_name'] != '') {
|
||||
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
|
||||
// Extract file details for this iteration
|
||||
$single_file = [
|
||||
'name' => $_FILES['file']['name'][$i],
|
||||
'type' => $_FILES['file']['type'][$i],
|
||||
'tmp_name' => $_FILES['file']['tmp_name'][$i],
|
||||
'error' => $_FILES['file']['error'][$i],
|
||||
'size' => $_FILES['file']['size'][$i]
|
||||
];
|
||||
|
||||
if ($file_reference_name = checkFileUpload($_FILES['file'], array('jpg', 'jpeg', 'gif', 'png', 'webp', 'pdf', 'txt', 'md', 'doc', 'docx', 'odt', 'csv', 'xls', 'xlsx', 'ods', 'pptx', 'odp', 'zip', 'tar', 'gz', 'xml', 'msg', 'json', 'wav', 'mp3', 'ogg', 'mov', 'mp4', 'av1'))) {
|
||||
if ($file_reference_name = checkFileUpload($single_file, array('jpg', 'jpeg', 'gif', 'png', 'webp', 'pdf', 'txt', 'md', 'doc', 'docx', 'odt', 'csv', 'xls', 'xlsx', 'ods', 'pptx', 'odp', 'zip', 'tar', 'gz', 'xml', 'msg', 'json', 'wav', 'mp3', 'ogg', 'mov', 'mp4', 'av1'))) {
|
||||
|
||||
$file_tmp_path = $_FILES['file']['tmp_name'][$i];
|
||||
|
||||
$file_tmp_path = $_FILES['file']['tmp_name'];
|
||||
$file_name = sanitizeInput($_FILES['file']['name'][$i]);
|
||||
$extarr = explode('.', $_FILES['file']['name'][$i]);
|
||||
$file_extension = sanitizeInput(strtolower(end($extarr)));
|
||||
|
||||
// directory in which the uploaded file will be moved
|
||||
$upload_file_dir = "uploads/clients/$client_id/";
|
||||
|
|
@ -38,17 +40,12 @@ if (isset($_POST['add_file'])) {
|
|||
//Logging
|
||||
$file_id = intval(mysqli_insert_id($mysqli));
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'File', log_action = 'Upload', log_description = '$file_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $file_id");
|
||||
|
||||
$_SESSION['alert_message'] = 'File successfully uploaded.';
|
||||
|
||||
} else {
|
||||
|
||||
$_SESSION['alert_message'] = 'There was an error moving the file to upload directory. Please make sure the upload directory is writable by web server.';
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect at the end, after processing all files
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['delete_file'])) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue