How to move all the files from one directory to another in PHP

1 Answer

0 votes
function move_files($src, $dst) 
{ 
    $handle = opendir($src);                     
    if (!is_dir($dst)) mkdir($dst, 0755);  

    while ($file = readdir($handle)) 
    { 
        if (($file != ".") and ($file != "..")) 
        {       
            $src_path = $src."/".$file; 
            $dst_path = $dst."/".$file; 
            if (is_dir($src_path)) 
            {                     
                move_files($src_path, $dst_path);               
            } 
            else 
            { 
                copy($src_path, $dst_path); 
                unlink($src_path);                        
            }                                            
        } 
    } 
    closedir($handle); 
    rmdir($src);                                    
} 

move_files("d:\\test", "d:\\test_1");


answered Aug 31, 2014 by avibootz

Related questions

2 answers 228 views
1 answer 241 views
1 answer 191 views
1 answer 220 views
3 answers 282 views
3 answers 268 views
...