本文整理汇总了PHP中RecursiveDirectoryIterator::getSubPathName方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveDirectoryIterator::getSubPathName方法的具体用法?PHP RecursiveDirectoryIterator::getSubPathName怎么用?PHP RecursiveDirectoryIterator::getSubPathName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveDirectoryIterator
的用法示例。
在下文中一共展示了RecursiveDirectoryIterator::getSubPathName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copy
/**
* copies a file or directory
*
* @param string $source
* @param string $dest
* @param bool $overwrite
*
* @throws FileException
* @throws InvalidStateException
*/
public static function copy($source, $dest, $overwrite = true)
{
if (stream_is_local($source) && !file_exists($source)) {
throw new FileException("File or directory [{$source}] not found.");
} else {
if (!$overwrite && file_exists($dest)) {
throw new InvalidStateException("File or directory [{$dest}] already exists.");
} else {
if (is_dir($source)) {
static::createDir($dest);
foreach (new \FilesystemIterator($dest) as $item) {
static::delete($item);
}
foreach (new \RecursiveIteratorIterator($iterator = new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item->isDir()) {
static::createDir($dest . '/' . $iterator->getSubPathName());
} else {
static::copy($item, $dest . '/' . $iterator->getSubPathName());
}
}
}
}
}
static::createDir(dirname($dest));
if (!is_dir($source) && @stream_copy_to_stream(fopen($source, 'r'), fopen($dest, 'w')) === false) {
throw new FileException("Unable to copy file '{$source}' to '{$dest}'.");
}
}