За последние 24 часа нас посетили 61472 программиста и 1740 роботов. Сейчас ищут 817 программистов ...

Подскажите функцию для копирования папки с одного места на д

Тема в разделе "Вопросы от блондинок", создана пользователем Белый волк, 28 сен 2008.

  1. Белый волк

    Белый волк Активный пользователь

    С нами с:
    11 авг 2008
    Сообщения:
    32
    Симпатии:
    0
    Подскажите, пожалуйста, функцию PHP для копирования папки с одного места на другое!
    Спасибо!
     
  2. Anonymous

    Anonymous Guest

    Нет такой.
     
  3. Koc

    Koc Активный пользователь

    С нами с:
    3 мар 2008
    Сообщения:
    2.253
    Симпатии:
    0
    Адрес:
    \Ukraine\Dnepropetrovsk
    что-то типа такого:

    PHP:
    1. <?php
    2.  
    3.   // copy a directory and all subdirectories and files (recursive)
    4.   // void dircpy( str 'source directory', str 'destination directory' [, bool 'overwrite existing files'] )
    5. function dircpy($basePath, $source, $dest, $overwrite = false){
    6.     if(!is_dir($basePath . $dest)) //Lets just make sure our new folder is already created. Alright so its not efficient to check each time... bite me
    7.     mkdir($basePath . $dest);
    8.     if($handle = opendir($basePath . $source)){        // if the folder exploration is sucsessful, continue
    9.         while(false !== ($file = readdir($handle))){ // as long as storing the next file to $file is successful, continue
    10.             if($file != '.' && $file != '..'){
    11.                 $path = $source . '/' . $file;
    12.                 if(is_file($basePath . $path)){
    13.                     if(!is_file($basePath . $dest . '/' . $file) || $overwrite)
    14.                     if(!@copy($basePath . $path, $basePath . $dest . '/' . $file)){
    15.                         echo '<font color="red">File ('.$path.') could not be copied, likely a permissions problem.</font>';
    16.                     }
    17.                 } elseif(is_dir($basePath . $path)){
    18.                     if(!is_dir($basePath . $dest . '/' . $file))
    19.                     mkdir($basePath . $dest . '/' . $file); // make subdirectory before subdirectory is copied
    20.                     dircpy($basePath, $path, $dest . '/' . $file, $overwrite); //recurse!
    21.                 }
    22.             }
    23.         }
    24.         closedir($handle);
    25.     }
    26. }
    27.  
    28. ?>