copy one folder to another location or another folder using php


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);
}
$src = '/path/of/source/';
$dst = '/path/to/destination/';
recurse_copy($src,$dst);

Advertisements

delete a folder with content using php


function remove_temp($dirname = '.')
{
if (is_dir($dirname))
{
if ($handle = @opendir($dirname))
{
while (($file = readdir($handle)) !== false)
{
if ($file != "." && $file != "..")
{
$fullpath = $dirname . '/' . $file;
if (is_dir($fullpath))
{
remove_temp($fullpath);
@rmdir($fullpath);
}
else
{
@unlink($fullpath);
}
}
}
closedir($handle);
}
rmdir($dirname);
}
}
remove_temp('path/to/delete/folder/here/');