Open hadleyrich opened 6 years ago
<?php
// Example PHP script handling file sorting in TYPO3 or similar CMS/framework
// Assuming a function to get the current directory path from request parameters or session
$currentDirectory = isset($_GET['dir']) ? $_GET['dir'] : '';
// Constructing the base path dynamically based on configuration or environment
$basePath = '/path/to/fileadmin'; // Replace with actual base path of fileadmin
// Ensure $currentDirectory is properly sanitized and validated to prevent directory traversal attacks
$fullPath = realpath($basePath . '/' . $currentDirectory);
if ($fullPath !== false && strpos($fullPath, $basePath) === 0) {
// Valid directory within fileadmin
$files = scandir($fullPath);
// Sort files based on sorting criteria (e.g., name, size, date)
$sortField = isset($_GET['sort']) ? $_GET['sort'] : 'name';
switch ($sortField) {
case 'name':
natcasesort($files); // Sort by name
break;
case 'size':
usort($files, function($a, $b) use ($fullPath) {
return filesize($fullPath . '/' . $a) - filesize($fullPath . '/' . $b);
});
break;
case 'date':
usort($files, function($a, $b) use ($fullPath) {
return filemtime($fullPath . '/' . $a) - filemtime($fullPath . '/' . $b);
});
break;
default:
// Default sorting logic
natcasesort($files); // Sort by name
break;
}
// Output sorted files
foreach ($files as $file) {
echo '<li>' . $file . '</li>';
}
} else {
echo 'Invalid directory path or access denied.';
}
?>
When trying to sort in a subdirectory in the fileadmin you are redirected to the base path. Pull request #1496 fixes this.