08 May 2008

PHP: Web File Manager



Lagi males ngomong, coba aja sendiri!
eh iya, karena penerimaan form-nya menggunakan variabel global secara sporadis, jadi harus mengubah setting dari php dulu untuk versi 5 keatas karena secara default mendisable global register. Ubah settingnya misal di file /etc/apache/php.ini sesuai instalasinya, ubah off menjadi on. Atau tambahkan penerimaan semua variabel get misal dengan $ind=$_GET[ind]; dibagian atasnya.

register_globals = on

source code:



<?php
{
$akses=9;
$skrip=$_SERVER['PHP_SELF']."?";
$rootDir=".";
$homeDir="$rootDir";
$Jenis=$homeDir;
echo "Home direktori anda : ".$homeDir;
}


/* Example: */ //dironly ('.','','.') //fileonly('.','.','') //htmlonly('.','.html','') //w/o html('.','','.html')
function fileList($dir,$ikut0,$lewat0){
$hasil=array();
$ikut=explode(' ',$ikut0);
$lewat=explode(' ',$lewat0);
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$ikutya=0;
$lewatya=0;
foreach ($ikut as $i => $value ){
if(strripos($file,$value)!==false && $value!='.')$ikutya=1;
else if($value=='.' && is_dir("$dir\$file"))$ikutya=1;
}
foreach ($lewat as $i => $value ){
if(strripos($file,$value)!==false && $value!='.')$lewatya=1;
else if($value=='.' && is_dir("$dir\$file"))$lewatya=1;
}
if($ikut0=='')$ikutya=1;
if($lewat0=='')$lewatya=0;
if($ikutya==1&&$lewatya==0)$hasil[]=$file;//));htmlentities(rawurlencode(
}
}
closedir($handle);
}
return $hasil;
}


if(isset($op)&&$akses>=5){
$asal=dirname($ind);
switch($op){
case "tambahDir":
if(isset($D0)){
if(mkdir(("$ind/$D0"))){
echo "<script>alert('berhasil membuat $ind/$D0')</script>";
$handle=touch("$ind/$D0/index.html");
}else
echo "<script>alert('Gagal membuat $ind/$D0')</script>";
echo"<script>location.assign('$skrip&ind=$ind/$D0'); </script>";
}else{
echo"
<script>
var D0=prompt('Masukkan nama direktori baru','');
if(D0!=null && D0.length>0){location.assign('$skrip&op=$op&ind=$ind&D0='+D0);}
else {history.go(-2);}
</script>
";
}
break;
case "tambahFile":
if(isset($D3)){
$file=$_FILES['D3']['name'];
$newfile=($ind."/".$file);//str_replace(" ","_",$file);
if (move_uploaded_file($_FILES['D3']['tmp_name'], $newfile)) {
echo "<script>alert('berhasil menambah $newfile')</script>";
}else{
echo "<script>alert('gagal menambah $newfile')</script>";
}
echo"<script>location.assign('$skrip&ind=$ind'); </script>";
}else{

?>
<table><tr align=center><td colspan=2>Upload File di <? echo $ind; ?><br><br></td></tr>
<form method="POST" enctype="multipart/form-data" action="<?php echo "$skrip&ind=$ind&op=$op" ?>">
<input type=hidden name="D0" values="user">
<input type=hidden name="D1" value="<? echo date("H:i:s j/m/y") ?>" >
<tr><td >Keterangan:</td><td ><input type=text name="D2"></td></tr>
<tr><td>File:</td><td> <input type=file name="D3">
</td></tr>
<tr><td colspan=2><input type=submit name="ok" value="Simpan"></td></tr>
</table>
</form>
<?
}
break;
case "hapus":
if(is_dir($ind)){
if(file_exists("$ind/index.html"))unlink("$ind/index.html");
if(rmdir("$ind"))echo "<script>alert('berhasil menghapus $ind');</script>";
else echo "<script>alert('gagal menghapus $ind, direktori belum kosong');</script>";
}else{
if(unlink("$ind"))echo "<script>alert('berhasil menghapus $ind');</script>";
else echo "<script>alert('gagal menghapus $ind');</script>";
}
echo"<script>location.assign('$skrip&ind=".dirname($ind)."'); </script>";
break;
case "rename":
if(isset($D0)){
if(rename($ind,dirname($ind)."/$D0")){
echo "<script>alert('berhasil merename $ind/$D0')</script>";
}else
echo "<script>alert('Gagal merename $ind/$D0')</script>";
echo"<script>location.assign('$skrip&ind=".dirname($ind)."'); </script>";
}else{
echo"
<script>
var D0=prompt('Masukkan nama file baru','');
if(D0!=null && D0.length>0){location.assign('$skrip&op=$op&ind=$ind&D0='+D0);}
else {history.go(-2);}
</script>
";
}
}
}else{
if(!isset($ind)||strstr($ind,$homeDir)==false)$ind=$homeDir;
echo"<table border=1 width=100%>
<tr><td colspan=3 align=center>&nbsp;<font class=title>".strtoupper(substr(strrchr($ind, "/"), 1))."</font></td></tr>
<tr><td colspan=2><a href='$skrip'>[Home]</a>";
$indJudul=str_replace($homeDir,"",$ind);//buat judul
$arrInd=explode('/',$indJudul);
unset($Judul);
foreach($arrInd as $ieai=>$eai){
$Judul.="<a href='$skrip&ind=$Jenis";
for($iieai=0;$iieai<=$ieai;$iieai++){
$Judul.=($arrInd[$iieai]);
if($iieai<$ieai)$Judul.="/";
}
$Judul.="'>$eai</a>/";
}
echo ($Judul)."</td>";

if($akses>=5)echo"<td width=10><a href='$skrip&ind=".($ind)."&op=tambahDir'>TambahDir</a> <a href='$skrip&ind=".($ind)."&op=tambahFile'>TambahFile</a> </td>";
echo"</tr>
<tr align=center><td>Nama</td>
<td>Ukuran</td>";
if($akses>=5)echo"<td>Operasi</td>";
echo"</tr>
";

$arsip=fileList("$ind",'','index.html');//tampilkan isi
foreach($arsip as $iArsip=>$cArsip){
$test=(($ind)."/".($cArsip));
echo"<tr><td>";
if(is_dir(($test)))echo"<a href='$skrip&ind=".rawurlencode($test)."'>$cArsip</a>";//rawurldecode
else echo"<a href='".($test)."'>".($cArsip)."</a>";
$ukuran=filesize($test);
if(is_dir($test)){
$ukuran="";
}else if($ukuran>=1000000){
$ukuran=$ukuran/1000000;
$ukuran=round($ukuran,2);
$ukuran=$ukuran." MB";
}else if($ukuran>=1000){
$ukuran=$ukuran/1000;
$ukuran=round($ukuran,2);
$ukuran=$ukuran." KB";
}else{
$ukuran=$ukuran." byte";
}
echo "</td>
<td>&nbsp;".$ukuran."</td>";
if($akses>=5)echo"<td><a href='$skrip&ind=$test&op=hapus'>Hapus</a> &nbsp;<a href='$skrip&ind=$test&op=rename'>Rename</a></td>";
echo"</tr>";
unset($row);
}
echo"</table><br/>";
}

?>


1 °C:

qu4ck said...

Thanks om ini yang tak cari... tapi masih kurang Edit file nya y...

Post a Comment