|
 |
|
รบกวนสอบถามเรื่องการแยกโฟล์ดเดอร์(ไม่น่ายากแต่ก็ยากสำหรับมือใหม่สำหรับผม) |
|
 |
|
|
 |
 |
|
critical_erase.php
Code (PHP)
<?PHP
if(isset($_GET['file'])){
echo str_replace("\n","<br />", htmlspecialchars(str_replace('><',">\n<", implode('', file($_GET['file'])))));
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Critical Erase </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Chaidhanan Pisalsenadhanachote" />
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<style type='text/css'>
a{color: #0000FF; text-decoration: none;}
a:visited{color: #0000FF; text-decoration: none;}
a:hover{color: #00bbbb; text-decoration: none;}
</style>
</head>
<body>
<font style="color:red;background-color:yellow;font-weight: bold"> !!!! คำเตือน !!!! </font><br />
<font style="color:yellow;background-color: red"> การลบ Directory อาจทำให้ข้อมูลของท่าน สูญหายได้ </font><br />
<font style="color: #99FFFF;background-color: blue"> IP: <?php echo $_SERVER['REMOTE_ADDR'];?> </font><br />
<br />
<?php
$trusIP=array('/^127.0.0.1/'); // เพื่ม ip ที่ใช้ทำงานเข้าไปได้เรื่อย
if(preg_match( $trusIP, $_SERVER['REMOTE_ADDR'])){
function erase_dir($dir) {
foreach (glob($dir.'/*') as $filename) {
//---------------------------------------------------------------------------------------------//
//____________________ IMPORTANT MESSAGE__________________ //
//__________________________________________________________//
// critical_erase.php เป็นชื่อไฟล์นี้ มีความสำคัญ
// ถ้าเปลียนชื่อไฟล ช่วยเปลี่ยนชื่อที่ข้างล่างนี้ด้วย ไม่อย่างนั้น ไฟล์นี้อาจจะหายไปด้วยก็ได้ 5555
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(!preg_match('/critical_erase.php/', $filename)){
chmod($filename, 0777);
if(is_dir($filename)) { erase_dir($filename); echo "Erase Dir $filename<br />"; rmdir($filename); }
else { echo "Erase File $filename<br />"; unlink($filename); }
}
}
}
if(isset($_POST['action']) && isset($_POST['url']) && isset($_POST['parent'])){
$c_url=count($_POST['url']);
for($ii=0; $ii<$c_url; $ii++) {
$z=$_POST['url'][$ii]; chmod($z, 0777);
if(is_dir($z)) { erase_dir($z); echo "Erase Dir $z<br />"; rmdir($z); }
else { echo "Erase File $z<br />"; unlink($z); }
}
}
///////////////////////////////////////////////////////////
$parent=isset($_GET['parent'])? $_GET['parent'] : (isset($_POST['parent'])? $_POST['parent'] :'.');
$c_d=0; $c_f=0; $d=array(); $f=array();
foreach (glob($parent.'/*') as $filename) {
if(is_dir($filename)){ $d[$c_d]=$filename; $c_d++; }
else { $f[$c_f]=$filename; $c_f++; }
}
?>
<form method="post" action="">
<input type="hidden" name="parent" value="<? echo "$parent";?>"/>
<?
echo '<a href="?parent=.">hk_log</a><br />'; $y='';
if($parent>'.'){
$a=explode('/', $parent); $c_a=count($a); //unset($a[$c_a]); $z=implode('/', $a);
$z=$a[0]; $y=' ';
for($ii=1; $ii<$c_a; $ii++) {
$z.='/'.$a[$ii];
echo $y.'<a href="?parent='.$z.'">'.$a[$ii].'</a><br />';
$y.=' ';
}
}
for($ii=0; $ii<$c_d; $ii++){
$a=explode('/', $d[$ii]); $c_a=count($a)-1;
echo $y.'<input type="checkbox" name="url[]" value="'.$d[$ii].'" /><a href="?parent='.$d[$ii].'">['.$a[$c_a].']</a><br />';
}
for($ii=0; $ii<$c_f; $ii++){
$a=explode('/', $f[$ii]); $c_a=count($a)-1;
echo $y.'<input type="checkbox" name="url[]" value="'.$f[$ii].'" /><a href="?file='.$f[$ii].'" target="_blank">'.$a[$c_a].'</a><br />';
}
}else{
echo 'There is not trustee for U.';
}
?>
<br />
<input type="submit" name="action" value="Erase"/>
</form>
</body>
</html>
โค๊ดนี้เขียนขึ้นมา หลายปีแล้วครับ โปรดใช้ด้วยความระมัดระวังนะครับ
ผมเอาไว้ใช้ลบ directory หรือ file ที่สร้างด้วย user nobody บน linux นะครับ
จะลบไฟล์ได้เฉพาะ ภายใน ไดเรคทอรี่ ที่สร้างขึ้น
|
 |
 |
 |
 |
Date :
2014-07-04 12:57:16 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|