WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Directory cleanup - This script was created for those times when you've allowed a directory to be overloaded with temp or cache type files which all need to be deleted.
Categories : PHP, Filesystem Click here to Update Your Picture
Sarah King
Date : Apr 06th 2005
Grade : 3 of 5 (graded 3 times)
Viewed : 15549
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Sarah King
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?PHP
/* Directory Cleanup
* Author: Sarah King
* Date  : 7 April 2005
* http://sarahk.pcpropertymanager.com/blog/directory-clean-up/29/
*
* This script was created for those times when you've allowed a
* directory to be overloaded with temp or cache type files which all
* need to be deleted. I had one so big I couldn't ftp into it!
* This script cleaned it out for me and removed 17MB of 2k files
* - you do the math!
*/
$dir2clean = 'cache';

$test = false;
$more = false;
$output = '';
if (
$handle = opendir($dir2clean))
{
   
$header = "\n";

   
$i = 0;
   
/* This is the correct way to loop over the directory. */
   
while (false !== ($file = readdir($handle)) && $i < 105)
   {
           if (
$i < 100)
           {
           
$output .= "<tr><td>$file</td>\n<td>";
           if (
substr($file, 0, 1) != '.')
           {
                   if (
$test) $output .= 'test';
                elseif (
unlink("{$dir2clean}/{$file}")) $output .= "deleted";
                   else
$output .= "kept";
           }
           else
$output .= ' ';
           
           
$output .= "</td><td>";
           
$output .= date ("F d Y H:i:s.", fileatime("cache/{$file}"));
           
$output .= "</td>\n</tr>\n";
           }
           else
$more = true;

           
$i++;
   }
   
closedir($handle);
}
?>
<html>
<head>
<?PHP
// meta refresh can fail in Internet Explorer but this works like a rocket in Firefox
if ($more && !$test)
{
    echo
"\n<META HTTP-EQUIV='Refresh' CONTENT=\"1; URL=http://{$_SERVER['HTTP_HOST']}{$PHP_SELF}\">\n";
}
?>
</head>
<body>
<h2>Date: <?php echo date('d-m-Y H:i'); ?><br />
    Directory: <?=$dir2clean; ?><br />
    Files:</h2>

<table border='1' cellpadding="4" cellspacing="0">
<?php echo $output; ?>
</table>
</body>
</html>



Using PHP to Delete a directory with all sub directories and files using FTP
Categories : PHP, FTP, Directories, Filesystem
Working with files - putting file contents to a string / var
Categories : PHP, Filesystem, Variables, Strings
This script will read all images from a folder and read the files into an array. It uses rand() to get a random number. It will display a random image from the image folder given.
Categories : PHP, Arrays, Graphics, Filesystem
getDirArray(Path,Filter,Sorted): Returns an array of the files in a directory, filtered by regular expression and either sorted or randomized. Good for random pictures and graphics.
Categories : PHP, Filesystem, Directories
Keep() - maintenance function for backup folders
Categories : PHP, Filesystem, Maintenance
Download manager - A PHP script for adding a download page to any site.It also enables you track the no. of downloads.
Categories : PHP, Content Management, Filesystem, Databases, MySQL
Handle multiple file upload
Categories : Complete Programs, Filesystem, PHP, HTML and PHP
Directory viewer, customize how you display the file structure, easy to understand. Found out about PHP 3 days ago, and this is my first prog.
Categories : HTML and PHP, Complete Programs, Directories, Filesystem, PHP
basename -- Returns filename component of path
Categories : PHP, PHP Functions, Filesystem
Listing the 10 most recently updated files in a given dir by using last- modified variable and printing to html with link to the file
Categories : PHP, Directories, Filesystem
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
Selecting a random line from a text file
Categories : PHP, Filesystem, Arrays, Beginner Guides
Complete NotePad application for Websites (Like Yahoo Notepad)
Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs
A simple php file uploader
Categories : PHP, Filesystem, HTML and PHP
Email attachment code
Categories : PHP, Email, Filesystem