'ok']); exit; } /* ================= RENAME FILE ================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['rename_old'], $_POST['rename_new'])) { $old = realpath($_POST['rename_old']); $newName = basename($_POST['rename_new']); if ($old && strpos($old, $baseDir) === 0) { $newPath = dirname($old) . '/' . $newName; rename($old, $newPath); } echo "renamed"; exit; } /* ================= CHUNK UPLOAD ================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) { $name = basename($_POST['name']); $chunk = (int)$_POST['chunk']; $totalChunks = (int)$_POST['totalChunks']; $tmpFile = $dir . '/' . $name . '.part'; file_put_contents($tmpFile, file_get_contents($_FILES['file']['tmp_name']), FILE_APPEND); if ($chunk + 1 == $totalChunks) { rename($tmpFile, $dir . '/' . $name); } echo "chunk_ok"; exit; } /* ================= REMOTE UPLOAD ================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['remote_urls'])) { $urls = array_filter(array_map('trim', explode("\n", trim($_POST['remote_urls'])))); $mh = curl_multi_init(); $handles = []; foreach ($urls as $i => $url) { $filename = basename(parse_url($url, PHP_URL_PATH)) ?: 'file_' . time() . '_' . $i; $savePath = $dir . '/' . $filename; $fp = fopen($savePath, 'w+'); if (!$fp) continue; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_FILE => $fp, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => 0, CURLOPT_CONNECTTIMEOUT => 20, CURLOPT_USERAGENT => 'Mozilla/5.0', CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, ]); curl_multi_add_handle($mh, $ch); $handles[$i] = ['ch' => $ch, 'fp' => $fp, 'filename' => $filename]; } $running = null; do { curl_multi_exec($mh, $running); curl_multi_select($mh); } while ($running > 0); $downloaded = []; foreach ($handles as $h) { curl_multi_remove_handle($mh, $h['ch']); curl_close($h['ch']); fclose($h['fp']); $downloaded[] = $h['filename']; } curl_multi_close($mh); echo json_encode(['status' => 'ok', 'files' => $downloaded]); exit; } /* ================= LIST FILES ================= */ function listDirectory($dir) { $files = []; if (empty($dir) || !is_dir($dir)) return $files; foreach (scandir($dir) as $file) { if ($file === '.' || $file === '..') continue; $path = $dir . '/' . $file; if (!is_readable($path)) continue; $files[] = [ 'name' => $file, 'path' => $path, 'is_dir' => is_dir($path), 'size' => is_file($path) ? filesize($path) : 0, 'modified' => filemtime($path), 'ext' => strtolower(pathinfo($file, PATHINFO_EXTENSION)), ]; } usort($files, fn($a,$b) => $b['is_dir'] <=> $a['is_dir']); return $files; } $files = listDirectory($dir); /* ================= HELPERS ================= */ function formatSize($size) { if ($size >= 1073741824) return round($size / 1073741824, 2) . ' GB'; if ($size >= 1048576) return round($size / 1048576, 2) . ' MB'; if ($size >= 1024) return round($size / 1024, 2) . ' KB'; return $size . ' B'; } function getPublicUrl($filePath) { global $basePath, $baseUrl; return str_replace($basePath, $baseUrl, $filePath); } function fileIconClass($ext) { $map = [ 'mp4'=>'fa-file-video','mkv'=>'fa-file-video','avi'=>'fa-file-video','mov'=>'fa-file-video','webm'=>'fa-file-video', 'jpg'=>'fa-file-image','jpeg'=>'fa-file-image','png'=>'fa-file-image','gif'=>'fa-file-image','webp'=>'fa-file-image', 'zip'=>'fa-file-zipper','rar'=>'fa-file-zipper','7z'=>'fa-file-zipper', 'mp3'=>'fa-file-audio','wav'=>'fa-file-audio','ogg'=>'fa-file-audio', 'pdf'=>'fa-file-pdf', 'doc'=>'fa-file-word','docx'=>'fa-file-word', 'xls'=>'fa-file-excel','xlsx'=>'fa-file-excel', 'txt'=>'fa-file-lines','md'=>'fa-file-lines', 'php'=>'fa-file-code','js'=>'fa-file-code','html'=>'fa-file-code','css'=>'fa-file-code', ]; return $map[$ext] ?? 'fa-file'; } function fileColorClass($ext) { $videos = ['mp4','mkv','avi','mov','webm']; $images = ['jpg','jpeg','png','gif','webp']; $archives = ['zip','rar','7z']; $audio = ['mp3','wav','ogg']; $docs = ['pdf','doc','docx','xls','xlsx']; $code = ['php','js','html','css','txt','md']; if (in_array($ext, $videos)) return 'clr-video'; if (in_array($ext, $images)) return 'clr-image'; if (in_array($ext, $archives)) return 'clr-archive'; if (in_array($ext, $audio)) return 'clr-audio'; if (in_array($ext, $docs)) return 'clr-doc'; if (in_array($ext, $code)) return 'clr-code'; return 'clr-default'; } function isMedia($ext) { return in_array($ext, ['jpg','jpeg','png','gif','webp','mp4','webm','mp3','wav','ogg']); } $totalFiles = 0; $totalFolders = 0; $totalSize = 0; foreach ($files as $f) { if ($f['is_dir']) { $totalFolders++; } else { $totalFiles++; $totalSize += $f['size']; } } /* ================= BREADCRUMB ================= */ function buildBreadcrumb($dir, $baseDir) { $crumbs = []; $rel = str_replace($baseDir, '', $dir); $parts = array_filter(explode('/', $rel)); $path = $baseDir; $crumbs[] = ['name' => 'Root', 'path' => $baseDir]; foreach ($parts as $part) { $path .= '/' . $part; $crumbs[] = ['name' => $part, 'path' => $path]; } return $crumbs; } $breadcrumbs = buildBreadcrumb($dir, $baseDir); $parentDir = ($dir !== $baseDir) ? dirname($dir) : null; ?> SabiShares — File Manager
Logout
Files
Folders
Storage

This folder is empty

Name Size Modified Actions
.. (Go Up)