本文整理汇总了PHP中RecursiveIteratorIterator::isWritable方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator::isWritable方法的具体用法?PHP RecursiveIteratorIterator::isWritable怎么用?PHP RecursiveIteratorIterator::isWritable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveIteratorIterator
的用法示例。
在下文中一共展示了RecursiveIteratorIterator::isWritable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rmdir
/**
* Remove recursively the directory named by dirname.
*
* @param string $dirname Path to the directory
* @param boolean $followLinks Removes symbolic links if set to true
* @return boolean True if success otherwise false
* @throws Exception When the directory does not exist or permission denied
*/
public static function rmdir($dirname, $followLinks = false)
{
if (!is_dir($dirname) && !is_link($dirname)) {
throw new Exception(sprintf('Directory %s does not exist', $dirname));
}
if (!is_writable($dirname)) {
throw new Exception('You do not have renaming permissions');
}
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::CHILD_FIRST);
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if (!$iterator->isWritable()) {
throw new Exception(sprintf('Permission denied for %s', $iterator->getPathName()));
}
if ($iterator->isLink() && false === (bool) $followLinks) {
$iterator->next();
continue;
}
if ($iterator->isFile()) {
unlink($iterator->getPathName());
} else {
if ($iterator->isDir()) {
rmdir($iterator->getPathName());
}
}
}
$iterator->next();
}
unset($iterator);
return rmdir($dirname);
}
示例2: recursive_rmdir
private function recursive_rmdir($dirname, $followLinks = false)
{
if (is_dir($dirname) && !is_link($dirname)) {
if (!is_writable($dirname)) {
throw new Exception('You do not have renaming permissions!');
}
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::CHILD_FIRST);
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if (!$iterator->isWritable()) {
throw new Exception(sprintf('Permission Denied: %s.', $iterator->getPathName()));
}
if ($iterator->isLink() && false === (bool) $followLinks) {
$iterator->next();
}
if ($iterator->isFile()) {
unlink($iterator->getPathName());
} else {
if ($iterator->isDir()) {
rmdir($iterator->getPathName());
}
}
}
$iterator->next();
}
unset($iterator);
// Fix for Windows.
return rmdir($dirname);
} else {
throw new Exception(sprintf('Directory %s does not exist!', $dirname));
}
}
示例3: RecursiveRmdir
/**
* Recursively remove a directory
*
* @param string $dirname
* @param boolean $followSymlinks
* @return boolean
*/
function RecursiveRmdir($dirname, $followSymlinks = false)
{
if (is_dir($dirname) && !is_link($dirname)) {
if (!is_writable($dirname)) {
throw new \Exception(sprintf('%s is not writable!', $dirname));
}
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dirname), \RecursiveIteratorIterator::CHILD_FIRST);
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if (!$iterator->isWritable()) {
throw new \Exception(sprintf('%s is not writable!', $iterator->getPathName()));
}
if ($iterator->isLink() && $followLinks === false) {
$iterator->next();
}
if ($iterator->isFile()) {
@unlink($iterator->getPathName());
} elseif ($iterator->isDir()) {
@rmdir($iterator->getPathName());
}
}
$iterator->next();
}
unset($iterator);
return @rmdir($dirname);
} else {
throw new \Exception(sprintf('%s does not exist!', $dirname));
}
}