/*
Author : Evergreenphp
Date : 10-10-2008
Desc : This is will delete all the 'xml' files inside the $path_dir folder
not only that but also this code checks whether the file created before 10 mins
or else that files will not be deleted
h - hour, i - minutes, s - seconds, m - month, d - date of the month, Y - Year
*/
/* Configuration setting starts */
$path_dir = "/www/htdocs/phpdocs/missing_man/general";
$cdate = date("Y-m-d h:i:s",mktime(date("h"), date("i")-10, date("s"), date("m"), date("d"), date("Y")));
$file_type = "txt";
/* Configuration setting ends */
/* Function call */
Delete_file_withtime($path_dir, $cdate, $file_type);
/* Function Definition starts */
function Delete_file_withtime($path_dir, $cdate, $file_type){
$dh = opendir($path_dir);
while (($file = readdir($dh)) !== false) {
$ext_test = explode(".", $file);
echo "
".$date_access = date("Y-m-d h:i:s", fileatime($file));
$stcon_dt = strtotime($date_access);
$encon_dt = strtotime($cdate);
if($file != "." && $file != ".." && $ext_test[1] == $file_type) {
if($encon_dt > $stcon_dt){
//@unlink($file);
echo "success";
}
}
}
}
/* Function Definition ends */
?>
Showing posts with label Remove file. Show all posts
Showing posts with label Remove file. Show all posts
Friday, October 10, 2008
Tuesday, September 23, 2008
Remove files, folders nested, PHP
Note: Pls remove the prefix space on all the HTML tags, before compile this program.
/*
Author : evergreenphp
Website : http://evergreenphp.blogspot.com
Website Info : Lots of source code
FREEly available, in PHP, javascript, AJAX,
MySQL etc.,
Note : 1. Before using this program, pls take a backup of your file and folders
2. Give folder and file permission then only this code will work nice..
Description : This program is used to remove all the file and folder in a specified folder
*/
/* Configuration settings start */
$path_file = '/www/htdocs/evergreenphp';
/* 0 - files not deleted, 1 - files will be deleted */
$display_with_destroy_files = 1;
/* 0 - files not deleted, 1 - files will be deleted */
$display_with_destroy_folders = 1;
/* Configuration settings ends */
$file_folder_list = scan_Dir($path_file);
$Files_list_array = Organize_file_list($file_folder_list, $display_with_destroy_files);
$Folders_list_array = Organize_folder_list($file_folder_list, $display_with_destroy_folders);
echo "Current Folder : " . $path_file . "< br>" ;
echo "< br>Files Found : ".count($Files_list_array);
echo "< pre>";
print_r($Files_list_array);
echo "< /pre>";
echo "< br>Folders Found : ".count($Folders_list_array);;
echo "< pre>";
print_r($Folders_list_array);
echo "< /pre>";
/* ---------------------------------------------------------------------------- */
/* List out all files and folders in the Current Directory (Specific Directory) */
function scan_Dir($dir=".") {
$arrfiles = array();
if (is_dir($dir)) {
if ($handle = opendir($dir)) {
chdir($dir);
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($file)) {
//$arrfiles[] = $dir."/".$file;
$arr = scan_Dir($file);
$arrfiles[] = $dir."/".$file;
foreach ($arr as $value) {
$arrfiles[] = $dir."/".$value;
}
} else {
$arrfiles[] = $dir."/".$file;
}
}
}
chdir("../");
}
closedir($handle);
}
return $arrfiles;
}
/* Organize the files list */
function Organize_file_list($files_folders, $delete_status=0)
{
$Files_array = array();
for ($i=0; $i< count($files_folders); $i++)
{
$check = explode(".", $files_folders[$i]);
if (count($check) > 1) {
if($delete_status == 1)
@unlink($files_folders[$i]); /* Removing the files */
else
$Files_array[] = $files_folders[$i];
}
}
return $Files_array;
}
/* Organize the folders list */
function Organize_folder_list($files_folders, $delete_status=0)
{
$Files_array = array();
for ($i=0; $i< count($files_folders); $i++)
{
$check = explode(".", $files_folders[$i]);
if (count($check) == 1){
if($delete_status == 1)
@rmdir($files_folders[$i]); /* Removing the Folder */
else
$Files_array[] = $files_folders[$i];
}
}
return $Files_array;
}
?>
/*
Author : evergreenphp
Website : http://evergreenphp.blogspot.com
Website Info : Lots of source code
FREEly available, in PHP, javascript, AJAX,
MySQL etc.,
Note : 1. Before using this program, pls take a backup of your file and folders
2. Give folder and file permission then only this code will work nice..
Description : This program is used to remove all the file and folder in a specified folder
*/
/* Configuration settings start */
$path_file = '/www/htdocs/evergreenphp';
/* 0 - files not deleted, 1 - files will be deleted */
$display_with_destroy_files = 1;
/* 0 - files not deleted, 1 - files will be deleted */
$display_with_destroy_folders = 1;
/* Configuration settings ends */
$file_folder_list = scan_Dir($path_file);
$Files_list_array = Organize_file_list($file_folder_list, $display_with_destroy_files);
$Folders_list_array = Organize_folder_list($file_folder_list, $display_with_destroy_folders);
echo "Current Folder : " . $path_file . "< br>" ;
echo "< br>Files Found : ".count($Files_list_array);
echo "< pre>";
print_r($Files_list_array);
echo "< /pre>";
echo "< br>Folders Found : ".count($Folders_list_array);;
echo "< pre>";
print_r($Folders_list_array);
echo "< /pre>";
/* ---------------------------------------------------------------------------- */
/* List out all files and folders in the Current Directory (Specific Directory) */
function scan_Dir($dir=".") {
$arrfiles = array();
if (is_dir($dir)) {
if ($handle = opendir($dir)) {
chdir($dir);
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($file)) {
//$arrfiles[] = $dir."/".$file;
$arr = scan_Dir($file);
$arrfiles[] = $dir."/".$file;
foreach ($arr as $value) {
$arrfiles[] = $dir."/".$value;
}
} else {
$arrfiles[] = $dir."/".$file;
}
}
}
chdir("../");
}
closedir($handle);
}
return $arrfiles;
}
/* Organize the files list */
function Organize_file_list($files_folders, $delete_status=0)
{
$Files_array = array();
for ($i=0; $i< count($files_folders); $i++)
{
$check = explode(".", $files_folders[$i]);
if (count($check) > 1) {
if($delete_status == 1)
@unlink($files_folders[$i]); /* Removing the files */
else
$Files_array[] = $files_folders[$i];
}
}
return $Files_array;
}
/* Organize the folders list */
function Organize_folder_list($files_folders, $delete_status=0)
{
$Files_array = array();
for ($i=0; $i< count($files_folders); $i++)
{
$check = explode(".", $files_folders[$i]);
if (count($check) == 1){
if($delete_status == 1)
@rmdir($files_folders[$i]); /* Removing the Folder */
else
$Files_array[] = $files_folders[$i];
}
}
return $Files_array;
}
?>
Subscribe to:
Posts (Atom)
Popular Posts
-
1. How old PHP language is? - PHP began in 1994, so 14 years old. 2. What are different names of PHP? - PHP originally stood for Persona...
-
HTML: a. HTML is a markup language that is used to build static (non interactive and nonanimated) webpages. b. HTML is Case-Insensitive. So...
-
A payment gateway is an e-commerce application service provider service that authorizes payments for e-businesses, online retailers, bricks...
-
Note : This is not a perfect sort order, we have just displaying the list of PHP companies. 1. Photon Infotech No. 2/102, Arvind IT Park (N...
-
Hai all, Simple show hide sample using Show/Hide? Simple Show/Hide code
-
- count() -- Count elements in a variable - syntax for count() [int count ( mixed var [, int mode])] - If the optional mode parameter is set...
-
Sharing PHP, MySQL, Javascript, CSS Knowledge, We can share our PHP knowledge on the basis of PHP versioning, Javascript, AJAX, Stylesheet, ...
-
Use the below code and you can get the exact value in php as us saw in browser. Code: $encode_data = iconv('UTF-8', 'windows-125...
-
Download and Enjoy!
-
1. Rasmus Lerdorf Rasmus Lerdorf (born November 22, 1968 in Qeqertarsuaq, Greenland) is a Danish-Greenlandic programmer and is most notable ...