Copy folders (win & amp; linux)
Copy the folder to another place.
/**
- /**
- * Copy a folder
- Eg: copy wordpress under D:/wwwroot/
- D:/wwwroot/www/explorer/0000/del/1/
- You do not need to add a slash at the end. if the source folder name is not added to the copy address,
- The wordpress file is copied to D:/wwwroot/www/explorer/0000/del/1 /.
- * $ From = 'd:/wwwroot/wordpress ';
- * $ To = 'd:/wwwroot/www/explorer/0000/del/1/wordpress ';
- */
- Function copy_dir ($ source, $ dest ){
- $ Result = false;
- If (is_file ($ source )){
- If ($ dest [strlen ($ dest)-1] = '/'){
- $ __Dest = $ dest. "/". basename ($ source );
- } Else {
- $ __Dest = $ dest;
- }
- $ Result = @ copy ($ source, $ __dest );
- // Echo iconv ($ config ['app _ charset'], $ config ['system _ charset'], $ source );
- @ Chmod (__ dest, 0755 );
- } Elseif (is_dir ($ source )){
- If ($ dest [strlen ($ dest)-1] = '/'){
- $ Dest = $ dest. basename ($ source );
- @ Mkdir ($ dest );
- @ Chmod ($ dest, 0755 );
- } Else {
- @ Mkdir ($ dest, 0755 );
- @ Chmod ($ dest, 0755 );
- }
- $ DirHandle = opendir ($ source );
- While ($ file = readdir ($ dirHandle )){
- If ($ file! = "." & $ File! = ".."){
- If (! Is_dir ($ source. "/". $ file )){
- $ __Dest = $ dest. "/". $ file;
- } Else {
- $ __Dest = $ dest. "/". $ file;
- }
- $ Result = copy_dir ($ source. "/". $ file, $ __dest );
- }
- }
- Closedir ($ dirHandle );
- } Else {
- $ Result = false;
- }
- Return $ result;
- }
|