<?php
declare(strict_types=1);
session_start();
if (empty($_SESSION['miter'])) {
header('Location: ../../index.php');
exit;
}
function formatbytes(int $bytes, int $precision = 2): string {
$units = array('b', 'kb', 'mb', 'gb', 'tb');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = (int)min($pow, count($units) - 1);
$bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . ' ' . $units[$pow];
}
if (!function_exists('calculate_directory_size')) {
function calculate_directory_size(string $dir): int {
$total_size = 0;
$files = glob($dir . '/*');
if ($files !== false) {
foreach ($files as $path) {
if (is_file($path)) {
$total_size += filesize($path);
} elseif (is_dir($path) && function_exists('get_dir_size')) {
$total_size += get_dir_size($path);
}
}
}
return $total_size;
}
}
$images_count = count(glob('images/*.*') ?: []);
$images_dir_size = calculate_directory_size('images');
$images_size = formatbytes($images_dir_size);
$var_sort = $_GET['sort'] ?? '';
?>
<div class='tenon_header'>
<div class='tenon_header_td'>
<span class='title'>Upload <span style='opacity: 0.5;'>| images/</span></span>
</div>
</div>
<form name='upform' enctype='multipart/form-data' method='post' action='back/tenon/upload_images.php' target='_blank' onsubmit='setTimeout(function(){window.location.reload();},1500);'>
<div class='full_tenon_table'>
<div class='full_upload_td'>
<input type='file' name='imgfiles[]' id='imgfiles' class='upload_file_field' multiple>
</div>
</div>
<input type='submit' name='submit' class='full_submit_button' value='Upload Image(s)'>
</form>
<div class='bump'></div>
<div class='tenon_header'>
<div class='tenon_header_td_left'>
<span class='title'>Images <span style='opacity: 0.5;'>| <?php echo $images_count . " - " . $images_size; ?></span></span>
</div>
<div class='tenon_header_td_right'>
<?php if ($var_sort === 'date') { ?>
<a href='?u=tenon_images&sort=abc'><img src='images/icons/sort_abc.png' class='tenon_list_button' alt='abc'></a> <img src='images/icons/sort_date.png' class='tenon_list_button' alt='date'>
<?php } else { ?>
<img src='images/icons/sort_abc.png' class='tenon_list_button' alt='abc'><a href='?u=tenon_images&sort=date'><img src='images/icons/sort_date.png' class='tenon_list_button' alt='date'></a>
<?php } ?>
</div>
</div>
<div class='tenon_table'>
<div class='tenon_td'>
<?php
if (function_exists('isMobile') && isMobile()) {
$char_count = 25;
} else {
$char_count = 45;
}
$i = 1;
$file_list = glob("images/*.*");
if ($file_list !== false) {
if ($var_sort === 'date') {
usort($file_list, function($newest, $oldest) {
return filemtime($oldest) <=> filemtime($newest);
});
}
foreach ($file_list as $file_name) {
$file_name = str_replace("images/", "", $file_name);
$file_loc = "images/" . $file_name;
if (file_exists($file_loc) && is_file($file_loc)) {
$file_size = filesize($file_loc);
$display_size = formatbytes($file_size !== false ? $file_size : 0);
?>
<div class='list_doc'>
<div class='list_doc_left'>
<span class='text'><?php echo $i++; ?>. </span>
<a href='images/<?php echo htmlspecialchars($file_name, ENT_QUOTES, 'UTF-8'); ?>' target='_blank'><?php echo htmlspecialchars(substr($file_name, 0, $char_count), ENT_QUOTES, 'UTF-8'); ?></a>
</div>
<span class='span_right'>
<span class='grey'><?php echo htmlspecialchars($display_size, ENT_QUOTES, 'UTF-8'); ?></span>
<a href='back/tenon/delete_image.php?d=<?php echo urlencode($file_name); ?>' onclick='return confirm_delete()'>
<img src='images/icons/delete_line.png' class='tenon_list_button_end' alt='delete'>
</a>
</span>
</div>
<?php
}
}
}
?>
</div>
</div>