File "test08.php"

Full Path: /home/analogde/www/DCIM/Auto/CHESS_2022/test08.php
File size: 3.03 KB
MIME-type: text/x-php
Charset: utf-8

<?php


function delete_folder()
{

	chdir("Utilisateurs");

	$dossier = 'alpha';
	$dir_iterator = new RecursiveDirectoryIterator($dossier);
	$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::CHILD_FIRST);

	// On supprime chaque dossier et chaque fichier	du dossier cible
	foreach($iterator as $fichier)
	{
		$fichier->isDir() ? rmdir($fichier) : unlink($fichier);
	}

	// On supprime le dossier cible
	rmdir($dossier);

}

//Recursive Copy of Directory

/**
 * Recursively move files from one directory to another
 * 
 * @param String $src - Source of files being moved
 * @param String $dest - Destination of files being moved
 */
function rmove($src, $dest)
{

    // If source is not a directory stop processing
    if(!is_dir($src)) return false;

    // If the destination directory does not exist create it
    if(!is_dir($dest)) { 
        if(!mkdir($dest)) {
            // If the destination directory could not be created stop processing
            return false;
        }    
    }

    // Open the source directory to read in files
    $i = new DirectoryIterator($src);
    foreach($i as $f) {
        if($f->isFile()) {
            rename($f->getRealPath(), "$dest/" . $f->getFilename());
        } else if(!$f->isDot() && $f->isDir()) {
            rmove($f->getRealPath(), "$dest/$f");
            unlink($f->getRealPath());
        }
    }
    unlink($src);
}


/**
 * Recursively copy files from one directory to another
 * 
 * @param String $src - Source of files being moved
 * @param String $dest - Destination of files being moved
 */
function rcopy($src, $dest)
{

    // If source is not a directory stop processing
    if(!is_dir($src)) return false;

    // If the destination directory does not exist create it
    if(!is_dir($dest)) { 
        if(!mkdir($dest)) {
            // If the destination directory could not be created stop processing
            return false;
        }    
    }

    // Open the source directory to read in files
    $i = new DirectoryIterator($src);
    foreach($i as $f) {
        if($f->isFile()) {
            copy($f->getRealPath(), "$dest/" . $f->getFilename());
        } else if(!$f->isDot() && $f->isDir()) {
            rcopy($f->getRealPath(), "$dest/$f");
        }
    }
}


/////// copie recursive 

if (isset($_POST['submit'])) { 
    function recurse_copy($src,$dst) {  
        $dir = opendir($src); 
        @mkdir($dst);  
        while(false !== ( $file = readdir($dir)) ) { 
            if (( $file != '.' ) && ( $file != '..' )) { 
                if ( is_dir($src . '/' . $file) ) { 
                    recurse_copy($src . '/' . $file,$dst . '/' . $file); 
                } 
                else { 
                    copy($src . '/' . $file,$dst . '/' . $file); 
                } 
            } 
        } 
        closedir($dir); 
        //echo "$src"; 
    } 
if (!is_dir($dst)) mkdir($dst, 0777); 
$src = "/home/user/public_html/dir/subdir/source_folder/";  
$dst = "/home/user/public_html/dir/subdir/destination_folder/";  
recurse_copy($src,$dst); 
}  

/////////////////////////