"Missing token."]); exit; } // Load share folder records. $shareFile = META_DIR . "share_folder_links.json"; if (!file_exists($shareFile)) { http_response_code(404); echo json_encode(["error" => "Share link not found."]); exit; } $shareLinks = json_decode(file_get_contents($shareFile), true); if (!is_array($shareLinks) || !isset($shareLinks[$token])) { http_response_code(404); echo json_encode(["error" => "Share link not found."]); exit; } $record = $shareLinks[$token]; // Check expiration. if (time() > $record['expires']) { http_response_code(403); echo json_encode(["error" => "This link has expired."]); exit; } // If password protection is enabled and no password is provided, show password form. if (!empty($record['password']) && empty($providedPass)) { ?> Enter Password

Folder Protected

This folder is protected by a password.

"Invalid password."]); exit; } } // Determine the folder path. $folder = trim($record['folder'], "/\\ "); $folderPath = rtrim(UPLOAD_DIR, '/\\') . DIRECTORY_SEPARATOR . $folder; $realFolderPath = realpath($folderPath); $uploadDirReal = realpath(UPLOAD_DIR); // Validate that the folder exists and is within UPLOAD_DIR. if ($realFolderPath === false || strpos($realFolderPath, $uploadDirReal) !== 0 || !is_dir($realFolderPath)) { http_response_code(404); echo json_encode(["error" => "Folder not found."]); exit; } // Scan and sort files. $allFiles = array_values(array_filter(scandir($realFolderPath), function($item) use ($realFolderPath) { return is_file($realFolderPath . DIRECTORY_SEPARATOR . $item); })); sort($allFiles); // Pagination variables. $itemsPerPage = 10; $totalFiles = count($allFiles); $totalPages = max(1, ceil($totalFiles / $itemsPerPage)); $currentPage = min($page, $totalPages); $startIndex = ($currentPage - 1) * $itemsPerPage; $filesOnPage = array_slice($allFiles, $startIndex, $itemsPerPage); /** * Convert file size in bytes into a human-readable string. * * @param int $bytes The file size in bytes. * @return string The formatted size string. */ function formatBytes($bytes) { if ($bytes < 1024) { return $bytes . " B"; } elseif ($bytes < 1024 * 1024) { return round($bytes / 1024, 2) . " KB"; } elseif ($bytes < 1024 * 1024 * 1024) { return round($bytes / (1024 * 1024), 2) . " MB"; } else { return round($bytes / (1024 * 1024 * 1024), 2) . " GB"; } } ?> Shared Folder: <?php echo htmlspecialchars($folder, ENT_QUOTES, 'UTF-8'); ?>

Shared Folder:

This folder is empty.

Filename Size

Upload File (50mb max size)