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
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



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 : Using PHP to Delete a directory with all sub directories and files using FTP
Categories : PHP, FTP, Directories, Filesystem Click here to Update Your Picture
Ahmed Samir
Date : May 22nd 2008
Grade : 4 of 5 (graded 4 times)
Viewed : 14783
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ahmed Samir
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

How to delete specific directory with all sub directories and files using FTP

<?php
////////////////////////////////////////////////////////
// del directory with all sub folders and files
// By:
// Ahmed Samir
// [email protected]
// www.asamir.net
//
////////////////////////////////////////////////////////

function ftp_delAll($conn_id,$dst_dir){
 
$ar_files = ftp_nlist($conn_id, $dst_dir);
 
//var_dump($ar_files);
 
if (is_array($ar_files)){ // makes sure there are files
     
for ($i=0;$i<sizeof($ar_files);$i++){ // for each file
         
$st_file = basename($ar_files[$i]);
          if(
$st_file == '.' || $st_file == '..') continue;
          if (
ftp_size($conn_id, $dst_dir.'/'.$st_file) == -1){ // check if it is a directory
             
ftp_delAll($conn_id$dst_dir.'/'.$st_file); // if so, use recursion
         
} else {
             
ftp_delete($conn_id$dst_dir.'/'.$st_file); // if not, delete the file
               
echo "delete <b><u>".$dst_dir."/".$st_file ." </u></b><br>";
          }
      }
     
sleep(1);
     
ob_flush() ;
  }
 
$flag = ftp_rmdir($conn_id, $dst_dir); // delete empty directories
   
 
return $flag;
}
// end of function ftp_delAll()


       // connect to FTP server
   
$ftp_user_name = 'FTP_User_name';
   
$ftp_user_pass = 'FTP_Password';
   
$ftp_server = 'FTP_Server';
   
$dst_dir = 'directory_path'; // this is relative path of directory you want to delete
   
$conn_id = @ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
   
       
// login into FTP server
   
if (@ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)) {
    echo
"Connected as $ftp_user_name@$ftp_server\n";
   
       
// call function ftp_delAll()
   
if(@ftp_delAll($conn_id,$dst_dir)){
    echo
"<br><br><font size=3><b>delete ok </b></font> ";
    }
   
    }else{
    echo
"Couldn't connect as $ftp_user\n";
    }
?>



Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML -
Categories : PHP, Directories, FTP, Filesystem, HTML and PHP
Open directory and File download
Categories : PHP, Filesystem, Directories, HTML and PHP
Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
A function which places the path and name of all subdirectories into an array
Categories : PHP, Filesystem, Arrays, Directories
List the content of the directory of your webserver where this small PHP Script resides.
Categories : PHP, Filesystem, Directories, CSS
a file explorer for the web, filesystem php php3 files dirs directories pictures files windows linux system list ls scripts
Categories : PHP, URLs, Directories, Filesystem
Moving folder hierarchy b/w server
Categories : PHP, FTP, Filesystem
grab directory listings into an array the example prints out each subdirectory in the main dir - further work is to be performed on this one
Categories : Filesystem, PHP, Directories, Search, Utilities
Fetching product details from the commission junction website using php
Categories : PHP, FTP, Filesystem, Compression
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
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
Upload function using PHP's FTP abilities.
Categories : PHP, Filesystem, FTP
A PHP Script that shows how to use FTP to run a shell script, read two local files and update data in a database.
Categories : PHP, Filesystem, FTP, Date Time, Databases
Display list of files within current and subdirectories (recursively) showing each file as an anchored link and each directory as a category header.
Categories : Filesystem, Directories, Arrays, PHP
Extended Get File List Function
Categories : PHP, Filesystem, Search, Directories