mirror of
https://github.com/itflow-org/itflow
synced 2026-07-23 00:40:45 +00:00
Move Guest Function formatBytes to root shared functions and use in files and files section in contact
This commit is contained in:
@@ -1044,7 +1044,7 @@ if (isset($_GET['contact_id'])) {
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$file_description = escapeHtml($row['file_description']);
|
||||
$file_size = escapeHtml($row['file_size']);
|
||||
$file_size_KB = round($file_size / 1024);
|
||||
$file_size_human = formatBytes($file_size);
|
||||
$file_mime_type = escapeHtml($row['file_mime_type']);
|
||||
$file_created_at = escapeHtml($row['file_created_at']);
|
||||
|
||||
@@ -1058,7 +1058,7 @@ if (isset($_GET['contact_id'])) {
|
||||
<div class="text-secondary"><?php echo $file_description; ?></div>
|
||||
</td>
|
||||
<td><?php echo $file_mime_type; ?></td>
|
||||
<td><span class="text-monospace"><?php echo $file_size_KB; ?></span> KB</td>
|
||||
<td class="text-monospace"><?= $file_size_human ?></td>
|
||||
<td><?php echo $file_created_at; ?></td>
|
||||
<td class="text-center">
|
||||
<a href="post.php?unlink_contact_from_file&contact_id=<?php echo $contact_id; ?>&file_id=<?php echo $file_id; ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" class="btn btn-secondary btn-sm" title="Unlink"><i class="fas fa-fw fa-unlink"></i></a>
|
||||
|
||||
@@ -598,7 +598,7 @@ $num_root_items = intval($row_root_files['num']) + intval($row_root_docs['num'])
|
||||
$file_reference_name= escapeHtml($row['file_reference_name']);
|
||||
$file_ext = escapeHtml($row['file_ext']);
|
||||
$file_size = intval($row['file_size']);
|
||||
$file_size_KB = number_format($file_size / 1024);
|
||||
$file_size_human = formatBytes($file_size);
|
||||
$file_mime_type = escapeHtml($row['file_mime_type']);
|
||||
$file_uploaded_by = escapeHtml($row['user_name']);
|
||||
$file_archived_at = escapeHtml($row['file_archived_at']);
|
||||
@@ -722,11 +722,11 @@ $num_root_items = intval($row_root_files['num']) + intval($row_root_docs['num'])
|
||||
$file_reference_name= $item['reference_name'];
|
||||
$file_icon = $item['icon'];
|
||||
$file_size = $item['size'];
|
||||
$file_size_KB = $file_size ? number_format($file_size / 1024) : 0;
|
||||
$file_size_human = formatBytes($file_size);
|
||||
$file_mime_type = $item['mime'];
|
||||
$file_uploaded_by = $item['created_by'];
|
||||
$file_created_at = $item['created_at'];
|
||||
$file_archived_at = $item['archived_at'];
|
||||
$file_archived_at = $item['archived_at'];
|
||||
|
||||
// Shared?
|
||||
$sql_shared = mysqli_query(
|
||||
@@ -768,7 +768,7 @@ $num_root_items = intval($row_root_files['num']) + intval($row_root_docs['num'])
|
||||
</a>
|
||||
</td>
|
||||
<td><?php echo $file_mime_type; ?></td>
|
||||
<td><?php echo $file_size_KB; ?> KB</td>
|
||||
<td><?php echo $file_size_human; ?></td>
|
||||
<td>
|
||||
<?php echo $file_created_at; ?>
|
||||
<div class="text-secondary mt-1"><?php echo $file_uploaded_by; ?></div>
|
||||
|
||||
@@ -825,7 +825,7 @@ ob_start();
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$file_description = escapeHtml($row['file_description']);
|
||||
$file_size = escapeHtml($row['file_size']);
|
||||
$file_size_KB = round($file_size / 1024);
|
||||
$file_size_human = formatBytes($file_size);
|
||||
$file_mime_type = escapeHtml($row['file_mime_type']);
|
||||
$file_created_at = escapeHtml($row['file_created_at']);
|
||||
|
||||
@@ -839,7 +839,7 @@ ob_start();
|
||||
<div class="text-secondary"><?= $file_description ?></div>
|
||||
</td>
|
||||
<td><?= $file_mime_type ?></td>
|
||||
<td><?= $file_size_KB ?> KB</td>
|
||||
<td class="text-monospace"><?= $file_size_human ?></td>
|
||||
<td><?= $file_created_at ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
@@ -69,16 +69,3 @@ function getFileIcon($file_extension) {
|
||||
return 'file';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Formats bytes into human readable file sizes
|
||||
*/
|
||||
function formatBytes($bytes, $precision = 2) {
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
}
|
||||
|
||||
@@ -328,3 +328,16 @@ function validateDate($date) {
|
||||
}
|
||||
return date('Y-m-d'); // Fallback
|
||||
}
|
||||
|
||||
/*
|
||||
* Formats bytes into human readable file sizes
|
||||
*/
|
||||
function formatBytes($bytes, $precision = 2) {
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user