public function add($file, $name, $data, $item) { $data['__item'] = $item; $dir = $this->dir_path($item, null, $name, $data); $new_filename = $this->real_uploaded_filename($name, $data, basename($file)); IO_FS::mkdir($dir, null, true); return IO_FS::cp($file, $dir . '/' . $new_filename); }
/** * Копирует рекурсивно вместе со всеми подкаталогами и содержащимися в нем файлами * * @param string $from * @param string $to */ static function copy($from, $to) { IO_FS::cp($from, $to); }
/** * @param stirng $path */ public static function extern_filepath($file, $copy = true, $link = false, $dest = null, $copy_dir = null) { $file = (string) $file; $prefix = self::option('extern_file_prefix'); if (Core_Strings::starts_with($file, $prefix)) { $res = str_replace($prefix, '', $file); if (is_null($dest)) { $res_name = ltrim(str_replace(Core::tao_dir(), '', $res), '/.'); } else { $res_name = rtrim($dest, '/.') . '/' . basename($file); } if ($copy == false) { return $res; } $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); $paths = Templates_HTML::option('paths'); $mtime = @filemtime($res); if ($mtime) { $dir = trim(is_null($copy_dir) ? self::option('copy_dir') : $copy_dir, '/'); $root = $paths['_fallback']; if (isset($paths[$ext])) { $root = $paths[$ext]; } $base_dir = trim($root . '/' . $dir, '/'); $path = sprintf('%s/%s', $base_dir, $res_name); $dir = dirname($path); if (!is_dir($dir)) { IO_FS::mkdir($dir); } $url = '/' . ltrim($path, '.'); if ($link) { if (!is_link($path)) { if (is_file($path)) { IO_FS::rm($path); } symlink(realpath($res), $path); } else { $link_path = readlink($path); if (!is_file($link_path) || realpath($link_path) != realpath($res)) { unlink($path); symlink(realpath($res), $path); } } return $url; } else { $mtime_exists = @filemtime($path); if ($mtime > $mtime_exists && IO_FS::cp($res, $path) || IO_FS::exists($path)) { return $url; } } } else { return $res; } } return $file; }