if (!$readonly) if ($action === 'mkdir' && isset($_POST['name'])) $newdir = $full_path . '/' . basename($_POST['name']); if (!file_exists($newdir)) mkdir($newdir, 0755);
// Root path for file manager $root_path = $_SERVER['DOCUMENT_ROOT'];
header('WWW-Authenticate: Basic realm="TinyFileManager"'); header('HTTP/1.0 401 Unauthorized'); echo 'Authentication required'; exit;
// Simple auth check function auth($users, $read_only_users = array()) if (!isset($_SESSION['loggedin'])) if (isset($_SERVER['PHP_AUTH_USER']) && isset($users[$_SERVER['PHP_AUTH_USER']])) $pass = $_SERVER['PHP_AUTH_PW']; $hash = $users[$_SERVER['PHP_AUTH_USER']]; if (password_verify($pass, $hash)) $_SESSION['loggedin'] = $_SERVER['PHP_AUTH_USER']; $_SESSION['readonly'] = in_array($_SERVER['PHP_AUTH_USER'], $read_only_users); return true; tinyfilemanager 2.4.3
// ============================================= // DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU DO // =============================================
function list_directory($path, $show_hidden) $files = scandir($path); $result = array('dirs' => array(), 'files' => array()); foreach ($files as $file) $file === '..') continue; if (!$show_hidden && $file[0] === '.') continue; $full = $path . '/' . $file; if (is_dir($full)) $result['dirs'][] = $file; else $result['files'][] = $file;
// Allowed extensions (empty = all) $allowed_extensions = array( 'jpg','jpeg','png','gif','pdf','txt','doc','docx','xls','xlsx', 'zip','tar','gz','mp3','mp4','php','html','css','js' ); '/' . ltrim($current_path
// Read-only users $read_only_users = array('user');
if ($action === 'delete' && isset($_POST['file'])) $target = $full_path . '/' . basename($_POST['file']); if (is_file($target)) unlink($target); if (is_dir($target)) array_map('unlink', glob($target . '/*')) && rmdir($target);
exit;
// Main logic $current_path = isset($_GET['path']) ? $_GET['path'] : ''; $full_path = $root_path . '/' . ltrim($current_path, '/'); $full_path = realpath($full_path);
// Upload file size limit (in bytes) $upload_max_size = 50 * 1024 * 1024; // 50MB