You are here: File deleter « All PHP « IT news, forums, messages
File deleter

Posted by Andy on 02/04/07 01:00

I have many pictures in the folder. Some of them I want to delete. Because
my FTP server shows only 1000 pictures, I am using following script.
Unfortunately it deletes single files only and it takes a time to reload
after deleting.
What I want is your help to modify this script so I would make check marks
at the file and than press a button to delete selected files.
I am sure there are people who would do it without a problem.
Your help will be appreciated.

Andy.

<?php
#########################################
# TheDeleter v1.0 #
# www.magtrb.com #
# www.magtrb.com/en #
# 20/09/06 23:33 #
# #
#########################################

session_start();
$secret = "123"; // Cpanel password
languge(English); //The Language.. English, Arabic ...


####### Don't write any thing below this line ##############
############################################################


if($_GET["logout"]){
session_destroy();
unset ($_SESSION['secret']);
unset ($_SESSION['code']);
echo"<script>
location = \"TheDeleter.php\";
</script>";
}

echo"<html dir=\""._De0."\">
<head>
<title>TheDeleter v1.0</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset="._De7."\">";
?>
<script>

function changedirpic(obj)
{
obj.src = "TheDeleter/directoryopen.gif";
}

function changedirpicback(obj)
{
obj.src = "TheDeleter/directory.gif";
}

</script>

<style type="text/css">

FONT {FONT-FAMILY: ms sans serif; FONT-SIZE: 12px}
BODY {FONT-FAMILY: ms sans serif;
FONT-SIZE: 12px;
background:#ffffff}
P {FONT-FAMILY: ms sans serif; FONT-SIZE: 14px}
DIV {FONT-FAMILY: ms sans serif; FONT-SIZE: 14px}

td {

color: #3C0954;
border: 1px solid #4B8CCF;
FONT-FAMILY: ms sans serif; FONT-SIZE: 14px
}
table {
margin-left: auto;
margin-right: auto;
background-color: #9CBFE3;
border: 2px solid #4B8CCF;
border-right: 2px solid #4B8CCF;
border-bottom: 2px solid #4B8CCF;
}
form {
padding: 0px;
margin: 0px;
}
A:link {color:#B63333;
FONT-SIZE: 12px;
FONT-FAMILY: ms sans serif;text-decoration:none}
A:active {color:#B63333;
FONT-SIZE: 12px;
FONT-FAMILY: ms sans serif;text-decoration:none}
A:visited {color:#B63333;
FONT-SIZE: 12px;
FONT-FAMILY: ms sans serif;text-decoration:none}
A:hover {color:#B63333;
FONT-SIZE: 12px;
FONT-FAMILY: ms sans serif;text-decoration:underline}
</style>

</head>

<body>

<br><br><table width="80%" border="0" >
<tr>
<td> <h2 align="center"><img src="TheDeleter/TheDeleter.gif"></h2> </td>
</tr><tr><td><br>

<?php
if($_SESSION['code'] !== $_POST['code'] && $_POST['loginkey']){

$text = $_SESSION['code']= strrand(5);

echo "<p align=\"center\"><b style=\"color: black\">"._De1."</b><br
/></p><br />\n";
echo "<form action=\"TheDeleter.php\" method=\"post\"> <p
align=\"center\">\n";
echo ""._De2." : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
style=\"background-color:
#CCCCCC\">$text</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
name=\"code\" type=\"text\" size=\"5\" maxlength=\"5\"><br>\n";
echo ""._De3." : <input name=\"secret\" type=\"password\"
size=\"20\"><br>\n";
echo "<input name=\"loginkey\" type=\"hidden\" value=\"loginkey\">\n";
echo "<input name=\"submit\" type=\"submit\" value=\""._De4."\">\n";
echo "</form><br><br>\n";
exit;

}
if ($_SESSION['secret'] !== $secret) {

if ($_POST['secret'] == $secret) {
$_SESSION['secret'] = $secret;
}
else {
$text = $_SESSION['code']= strrand(5);

echo "<p align=\"center\"><b style=\"color: black\">"._De1."</b><br
/></p><br />\n";
echo "<form action=\"TheDeleter.php\" method=\"post\"> <p
align=\"center\">\n";
echo ""._De2." : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
style=\"background-color:
#CCCCCC\">$text</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
name=\"code\" type=\"text\" size=\"5\" maxlength=\"5\"><br>\n";
echo ""._De3." : <input name=\"secret\" type=\"password\"
size=\"20\"><br>\n";
echo "<input name=\"loginkey\" type=\"hidden\" value=\"loginkey\">\n";
echo "<input name=\"submit\" type=\"submit\" value=\""._De4."\">\n";
echo "</form><br><br>\n";
exit;
}

}


if($_GET['submitunlink']){
echo"<table width=\"50%\">
<tr><td bgcolor=\"#C0C0C0\" align=\"center\">";
$dir_file = $_GET['unlink'];

if(str_replace('*', 'x', $dir_file) != $dir_file){

delfile($dir_file);

echo ""._De11."".$dir_file.""._De12."<br>";

}else{

if($dir_file == ''){

echo ""._De13."";

}else{

unlink($dir_file);

echo ""._De11."".$dir_file.""._De12."<br>";

}

}
echo"</td></tr>
</table><br>";
}

if($_GET['submitrmdir']){
echo"<table width=\"50%\" >
<tr><td bgcolor=\"#C0C0C0\" align=\"center\">";
$rm_dir = $_GET['rmdir'];

if($rm_dir == ''){

echo ""._De14."";

}else{

@SureRemoveDir($rm_dir);
@rm($rm_dir);
deleteDir($rm_dir) ;
echo ""._De15."".$rm_dir.""._De12." <br>";

}
echo"</td></tr>
</table><br>";
}

class displayer
{

var $allowclick = 0;

function checkSecure($directory)
{
if(strstr($directory, ".."))
{
return FALSE;
}

else
{
return TRUE;
}
}

function getPrevious()
{
$directory = $_GET['directory'];

$exdirectory = explode("/", $directory);

for($i=0; $i<count($exdirectory) - 1; $i++)
{
$output .= "/" . $exdirectory[$i];
}

$output = substr($output, 1);

return($output);
}

function displayList()
{

$maindir = $this->maindir;
$directory = $_GET['directory'];

if(!$this->checkSecure($directory))
{
return(""._De17."");
}

$output .= "<table border='0' cellpadding='5' cellspacing='0'>";

$output .= "<tr>";
$output .= "<td colspan='2'><a href='?directory=" . $this->getPrevious() .
"'>"._De18."</a></td>";
$output .= "</tr>";

$count = 0;

$dirname = $_SERVER["DOCUMENT_ROOT"] . $directory;

if(is_dir($_SERVER["DOCUMENT_ROOT"] . $directory))
{
$dir = opendir($dirname);

while(false != ($file = readdir($dir)))
{
$output .= "<tr>";

if(($file != ".") and ($file != ".."))
{
if(is_dir($_SERVER["DOCUMENT_ROOT"] . $directory . "/" . $file))
{
$output .= "<td><a href='?directory=" . $directory . "/" . $file .
"'><img onmouseover='changedirpic(this)' onmouseout='changedirpicback(this)'
border='0' width='16px' height='16px' src='TheDeleter/directory.gif'
/></a></td>";
$output .= "<td>" . $file . "</td>";
if(!empty($directory)){
$directoryxps = substr($directory, 1). "/"; }else{$directoryxps="";}
$output .= "<td><a href=\"TheDeleter.php?submitrmdir=xps&rmdir=" .
$directoryxps . "" . $file . "\">"._De19." $file</a></td>";
}

else
{
if($this->allowclick == 0)
{
$output .= "<td><img border='0' width='16px' height='16px'
src='TheDeleter/file.gif' /></td>";
}

else
{
$output .= "<td><a href='" . $directory . "/" . $file . "'><img
border='0' width='16px' height='16px' src='TheDeleter/file.gif'
/></a></td>";
}

$output .= "<td>" . $file . "</td>";
if(!empty($directory)){
$directoryxps = substr($directory, 1). "/"; }else{$directoryxps="";}

$output .= "<td><a
href=\"TheDeleter.php?submitunlink=xps&unlink=" . $directoryxps . "" . $file
.. "\">"._De19." $file</a></td>";
}

$count++;
}

$output .= "</tr>";
}
}

if($count == 0)
{
$output .= "<tr>";
$output .= "<td colspan='2'>"._De20."</td>";
$output .= "</tr>";
}

$output .= "</table>";

return($output);
}
}

$displayerHandler = new displayer();

$option = $_GET['option'];

if($option == null)
{
$option = "displaylist";
}

switch($option)
{ case "startsession":
echo($displayerHandler->startsession());
break;

case "displaylist":
echo($displayerHandler->displayList());
break;
}


echo"<br><hr width=\"70%\">
<div align=\"center\" style=\"color: #999999; font-size: 7pt;\">
[ <a href=\"TheDeleter.php\">"._De5."</a> ] -[ <a href=\""._De8."\"
target=\"_blank\">"._De9."</a> ]-[ <a
href=\"TheDeleter.php?logout=yes\">"._De10."</a> ]
</div><br>";
echo"</body></html>";





// the functions

function strrand($length)
{
$str = "";

while(strlen($str)<$length){
$random=rand(48,122);
if( ($random>47 && $random<58) ){
$str.=chr($random);
}

}

return $str;
}


function deleteDir($dir)
{
if (substr($dir, strlen($dir)-1, 1) != '/')
$dir .= '/';
// echo $dir;
if ($handle = opendir($dir))
{
while ($obj = readdir($handle))
{
if ($obj != '.' && $obj != '..')
{
if (is_dir($dir.$obj))
{
if (!deleteDir($dir.$obj))
return false;
}
elseif (is_file($dir.$obj))
{
if (!unlink($dir.$obj))
return false;
}
}
}
closedir($handle);
if (!@rmdir($dir))
return false;
return true;
}
return false;
}

function rm($fileglob)
{
if (is_string($fileglob)) {
if (is_file($fileglob)) {
return unlink($fileglob);
} else if (is_dir($fileglob)) {
$ok = rm("$fileglob/*");
if (! $ok) {
return false;
}
return rmdir($fileglob);
} else {
$matching = glob($fileglob);
if ($matching === false) {
trigger_error(sprintf('No files match supplied glob %s',
$fileglob), E_USER_WARNING);
return false;
}
$rcs = array_map('rm', $matching);
if (in_array(false, $rcs)) {
return false;
}
}
} else if (is_array($fileglob)) {
$rcs = array_map('rm', $fileglob);
if (in_array(false, $rcs)) {
return false;
}
} else {
trigger_error('Param #1 must be filename or glob pattern, or array of
filenames or glob patterns', E_USER_ERROR);
return false;
}
return true;
}

function SureRemoveDir($dir) {
if(!$dh = @opendir($dir)) return;
while (($obj = readdir($dh))) {
if($obj=='.' || $obj=='..') continue;
if (!@unlink($dir.'/'.$obj)) {
SureRemoveDir($dir.'/'.$obj);
} else {
$file_deleted++;
}
}
if (@rmdir($dir)) $dir_deleted++;
}

function delfile($str)
{
foreach(glob($str) as $fn) {
@unlink($fn);
}
}



function languge($spx){

switch ($spx) {
case English:
define("_De0","ltr");
define("_De1","Administrator Control Panel");
define("_De2","Security code");
define("_De3","Passowrd");
define("_De4","Enter");
define("_De5","Home");
define("_De6","left"); // direction of the text .. left or right
define("_De7","windows-1256");
define("_De8","http://www.magtrb.com/en");
define("_De9","Magtrb Soft");
define("_De10","Exit");
define("_De11","File:");
define("_De12"," was deleted.");
define("_De13","Please choose the file that you would like to delete.");
define("_De14","Please choose the directory that you would like to
delete.");
define("_De15","Directory: ");
define("_De17","Insecure directory.");
define("_De18","Parent Directory");
define("_De19","Delete");
define("_De20","No files or folders found.");

break;
case Arabic:
define("_De0","rtl");
define("_De1","لوحة التحكم");
define("_De2","الكود الامني");
define("_De3","الرقم السري");
define("_De4","دخول");
define("_De5","الرئيسية");
define("_De6","right"); // direction of the text ..
define("_De7","windows-1256");
define("_De8","http://www.magtrb.com");
define("_De9","مغترب");
define("_De10","خروج");
define("_De11","الملف:");
define("_De12","تم حذفه");
define("_De13","الرجاء اختيار الملف المراد حذفه.");
define("_De14","الرجاء اختيار المجلد المراد حذفه.");
define("_De15","المجلد: ");
define("_De17","مجلد غير محمي.");
define("_De18","المجلد الرئيسي");
define("_De19","حذف");
define("_De20","لا يوجد ملفات او مجلدات.");
break;
case xxx:
break;
}



}

?>

 

Navigation:

[Reply to this message]


ذ£ذ´ذ°ذ»ذµذ½ذ½ذ°رڈ ر€ذ°ذ±ذ¾ر‚ذ° ذ´ذ»رڈ ذ؟ر€ذ¾ذ³ر€ذ°ذ¼ذ¼ذ¸رپر‚ذ¾ذ²  •  ذڑذ°ذ؛ ذ·ذ°ر€ذ°ذ±ذ¾ر‚ذ°ر‚رŒ ذ½ذ° Google AdSense  •  England, UK  •  رپر‚ذ°ر‚رŒذ¸ ذ½ذ° ذ°ذ½ذ³ذ»ذ¸ذ¹رپذ؛ذ¾ذ¼  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

ذ،ذ°ذ¹ر‚ ذ¸ذ·ذ³ذ¾ر‚ذ¾ذ²ذ»ذµذ½ ذ² ذ،ر‚رƒذ´ذ¸ذ¸ ذ’ذ°ذ»ذµذ½ر‚ذ¸ذ½ذ° ذںذµر‚ر€رƒر‡ذµذ؛ذ°
ذ¸ذ·ذ³ذ¾ر‚ذ¾ذ²ذ»ذµذ½ذ¸ذµ ذ¸ ذ؟ذ¾ذ´ذ´ذµر€ذ¶ذ؛ذ° ذ²ذµذ±-رپذ°ذ¹ر‚ذ¾ذ², ر€ذ°ذ·ر€ذ°ذ±ذ¾ر‚ذ؛ذ° ذ؟ر€ذ¾ذ³ر€ذ°ذ¼ذ¼ذ½ذ¾ذ³ذ¾ ذ¾ذ±ذµرپذ؟ذµر‡ذµذ½ذ¸رڈ, ذ؟ذ¾ذ¸رپذ؛ذ¾ذ²ذ°رڈ ذ¾ذ؟ر‚ذ¸ذ¼ذ¸ذ·ذ°ر†ذ¸رڈ