Ejemplo n.º 1
0
 function mkdir($dir, $perm, $parents = true)
 {
     $dir = dir::clean_path($dir);
     if (!$parents) {
         return dir::_do_mkdir($dir, $perm);
     }
     $separator = dir::separator();
     $dir_elements = dir::explode_path($dir);
     if (count($dir_elements) == 0) {
         return true;
     }
     $current_dir = $dir_elements[0];
     if (!dir::_do_mkdir($current_dir, $perm)) {
         return false;
     }
     for ($i = 1; $i < count($dir_elements); ++$i) {
         $dir_element = $dir_elements[$i];
         $current_dir .= $separator . $dir_element;
         if (!dir::_do_mkdir($current_dir, $perm)) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 function cp($src, $dest, $as_child = false, $exclude_regex = '', $include_hidden = false)
 {
     $src = dir::clean_path($src);
     $dest = dir::clean_path($dest);
     if (!is_dir($src)) {
         debug::write_error('no such a directory', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('dir' => $src));
         return false;
     }
     if (!dir::mkdir($dest)) {
         return false;
     }
     $separator = dir::separator();
     if ($as_child) {
         $separator_regex = preg_quote($separator);
         if (preg_match("#^.+{$separator_regex}([^{$separator_regex}]+)\$#", $src, $matches)) {
             dir::_do_mkdir($dest . $separator . $matches[1], 0777);
             $dest .= $separator . $matches[1];
         } else {
             return false;
         }
         //???
     }
     $items = dir::find_subitems($src, 'df', $exclude_regex, false, $include_hidden);
     $total_items = $items;
     while (count($items) > 0) {
         $current_items = $items;
         $items = array();
         foreach ($current_items as $item) {
             $full_path = $src . $separator . $item;
             if (is_file($full_path)) {
                 copy($full_path, $dest . $separator . $item);
             } elseif (is_dir($full_path)) {
                 dir::_do_mkdir($dest . $separator . $item, 0777);
                 $new_items = dir::find_subitems($full_path, 'df', $exclude_regex, $item, $include_hidden);
                 $items = array_merge($items, $new_items);
                 $total_items = array_merge($total_items, $new_items);
                 unset($new_items);
             }
         }
     }
     if ($total_items) {
         clearstatcache();
     }
     return $total_items;
 }