本文整理汇总了PHP中lchown函数的典型用法代码示例。如果您正苦于以下问题:PHP lchown函数的具体用法?PHP lchown怎么用?PHP lchown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lchown函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: chown
/**
* Change the owner of an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change owner
* @param string $user The new owner user name
* @param bool $recursive Whether change the owner recursively or not
*
* @throws IOException When the change fail
*/
public function chown($files, $user, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chown(new \FilesystemIterator($file), $user, true);
}
if (is_link($file) && function_exists('lchown')) {
if (true !== @lchown($file, $user)) {
throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
}
} else {
if (true !== @chown($file, $user)) {
throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
}
}
}
}
示例2: chown
/**
* {@inheritdoc}
*/
public function chown($file, $user)
{
$file = $this->normalizePath($file);
return is_link($file) && function_exists('lchown') ? lchown($file, $user) : chown($file, $user);
}
示例3: changeOwner
/**
* Change file owner.
*
* @access public
* @param mixed $user User.
* @return bool
*/
public function changeOwner($user)
{
return lchown($this->getStreamName(), $user);
}
示例4: chown
/**
* Sets the owner for the fs resource
*
* @param mixed $owner
* @return boolean True if successful
*/
public function chown($owner)
{
if ($this->isLink() && function_exists('lchown')) {
return @lchown($this->path, $owner);
} else {
return @chown($this->path, $owner);
}
}
示例5: setChown
/**
* Change file owner
*
* Change a file owner to filepath
*
* @param string $path Path to the file
* @param string $user A file owner name or number UID
* @param bool $recursive Recursive set a group
* @return bool State of changes
* @throws \RuntimeException
*/
public function setChown($path, $user, $recursive = false)
{
$state = false;
if ($recursive) {
$iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
foreach ($iter as $val) {
if (is_link($val->getPathName())) {
if (!@lchown($path, $user)) {
throw new \Exception(sprintf("Can not change file owner for link %s with user %s", $path, $user));
}
$state = true;
} else {
if ($val->isFile()) {
if (!@chown($path, $user)) {
throw new \Exception(sprintf("Can not change file owner for file %s with user %s", $path, $user));
}
$state = true;
}
}
}
} else {
if (is_link($path)) {
if (!lchown($path, $user)) {
throw new Exception(sprintf("Can not change file owner for link %s with user %s", $path, $user));
}
$state = true;
} else {
if (is_file($path)) {
if (!chown($path, $user)) {
throw new Exception(sprintf("Can not change file owner for file %s with user %s", $path, $user));
}
$state = true;
}
}
}
return $state;
}
示例6: var_dump
var_dump(is_writable($path1));
var_dump(is_writeable($path1));
var_dump(is_readable($path1));
var_dump(is_executable($path1));
var_dump(is_file($path1));
var_dump(is_dir($path1));
var_dump(is_link($path1));
var_dump(file_exists($path1));
var_dump(stat($path1));
var_dump(lstat($path1));
var_dump(realpath($path1));
var_dump(disk_free_space($path1));
var_dump(diskfreespace($path1));
var_dump(disk_total_space($path1));
var_dump(chmod($path1, '644'));
var_dump(chown($path1, 'nobody'));
var_dump(lchown($path1, 'nobody'));
var_dump(chgrp($path1, 'nogrp'));
var_dump(lchgrp($path1, 'nogrp'));
var_dump(touch($path1));
var_dump(copy($path1, $path2));
var_dump(rename($path1, $path2));
var_dump(unlink($path1, $path2));
var_dump(link($path1, $path2));
var_dump(symlink($path1, $path2));
var_dump(fnmatch($path1, $path2));
var_dump(tempnam($path1, 'tmp'));
var_dump(mkdir($path1));
var_dump(chdir($path1));
var_dump(chroot($path1));
var_dump(scandir($path1));
示例7: extractCurrent
/**
* Extract the current entry to which the iterator points.
*
* Extract the current entry to which the iterator points, and return true if the current entry is extracted.
* If the iterator doesn't point to a valid entry, this method returns false.
*
* True if the file is extracted correctly, otherwise false.
*
* @param string $target
* The full path to which the target should be extracted.
* @param bool $keepExisting
* True if the file shouldn't be overwritten if they already exist.
* For the opposite behaviour, false should be given.
*
* @throws ezcArchiveValueException if the archive contains invalid values.
* @throws ezcBaseFileNotFoundException if the link cannot be found.
*
* @return bool
*/
public function extractCurrent($target, $keepExisting = false)
{
if ($this->file === null) {
throw new ezcArchiveException("The archive is closed");
}
if (!$this->valid()) {
return false;
}
$isWindows = substr(php_uname('s'), 0, 7) == 'Windows' ? true : false;
$entry = $this->current();
$type = $entry->getType();
$fileName = $target . DIRECTORY_SEPARATOR . $entry->getPath();
if ($type == ezcArchiveEntry::IS_LINK) {
$linkName = $target . DIRECTORY_SEPARATOR . $entry->getLink();
if (!file_exists($linkName)) {
throw new ezcBaseFileNotFoundException($linkName, "link", "Hard link could not be created.");
}
}
$this->createDefaultDirectory($fileName);
if (!$keepExisting || !is_link($fileName) && !file_exists($fileName)) {
if ((file_exists($fileName) || is_link($fileName)) && !is_dir($fileName)) {
unlink($fileName);
}
if (!file_exists($fileName)) {
switch ($type) {
case ezcArchiveEntry::IS_CHARACTER_DEVICE:
if (ezcBaseFeatures::hasFunction('posix_mknod')) {
posix_mknod($fileName, POSIX_S_IFCHR, $entry->getMajor(), $entry->getMinor());
} else {
throw new ezcArchiveValueException($type);
}
break;
case ezcArchiveEntry::IS_BLOCK_DEVICE:
if (ezcBaseFeatures::hasFunction('posix_mknod')) {
posix_mknod($fileName, POSIX_S_IFBLK, $entry->getMajor(), $entry->getMinor());
} else {
throw new ezcArchiveValueException($type);
}
break;
case ezcArchiveEntry::IS_FIFO:
if (ezcBaseFeatures::hasFunction('posix_mknod')) {
posix_mknod($fileName, POSIX_S_IFIFO);
} else {
throw new ezcArchiveValueException($type);
}
break;
case ezcArchiveEntry::IS_SYMBOLIC_LINK:
if ($isWindows) {
// FIXME.. need to be sure that target file
// already extracted before copying it to link destination.
$sourcePath = dirname($fileName) . '/' . $entry->getLink();
$fileName = str_replace('/', '\\', $fileName);
copy($sourcePath, $fileName);
} else {
symlink($entry->getLink(), $fileName);
}
break;
case ezcArchiveEntry::IS_LINK:
if ($isWindows) {
copy($target . DIRECTORY_SEPARATOR . $entry->getLink(), $fileName);
} else {
link($target . DIRECTORY_SEPARATOR . $entry->getLink(), $fileName);
}
break;
case ezcArchiveEntry::IS_DIRECTORY:
$permissions = $entry->getPermissions();
if ($permissions === null || $permissions === false) {
$permissions = '0777';
}
mkdir($fileName, octdec($permissions), true);
break;
case ezcArchiveEntry::IS_FILE:
$this->writeCurrentDataToFile($fileName);
break;
default:
throw new ezcArchiveValueException($type);
}
if ($type == ezcArchiveEntry::IS_SYMBOLIC_LINK && ezcBaseFeatures::hasFunction('posix_geteuid') && posix_geteuid() == 0) {
$user = $entry->getUserId();
$group = $entry->getGroupId();
@lchown($fileName, $user);
//.........这里部分代码省略.........
示例8: lchown
<?php
/* Prototype : bool lchown (string filename, mixed user)
* Description: Change file owner of a symlink
* Source code: ext/standard/filestat.c
* Alias to functions:
*/
echo "*** Testing lchown() : basic functionality ***\n";
$filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lchown_basic.txt';
$symlink = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lchown_basic_symlink.txt';
$uid = posix_getuid();
var_dump(touch($filename));
var_dump(symlink($filename, $symlink));
var_dump(lchown($filename, $uid));
var_dump(fileowner($symlink) === $uid);
?>
===DONE===
<?php
$filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lchown_basic.txt';
$symlink = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lchown_basic_symlink.txt';
unlink($filename);
unlink($symlink);
示例9: chownSingleFile
/**
* Change the owner of an array of files or directories.
*
* @internal services:
* (+) FilesystemInterface chown($files, string $user, bool $recursive = false);
*
* @param string $file The filename to change owner
* @param string $user The new owner user name
*
* @throws IOException When the change fails
*
* @return FilesystemInterface The current interface
*/
protected function chownSingleFile($file, string $user) : FilesystemInterface
{
if (is_link($file)) {
if (true !== @lchown($file, $user)) {
throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
}
} else {
if (true !== @chown($file, $user)) {
throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
}
}
return $this;
}
示例10: lchown
/**
* Changes user ownership of symlink
*
* @param string $filename Path to the file.
* @param mixed $user User name or number.
*
* @return bool
*/
public function lchown(string $filename, $user) : bool
{
return lchown($filename, $user);
}
示例11: chown
/**
* Change the owner of an array of files or directories.
*
* @param string|array|Traversable $files A filename, an array of files, or a Traversable instance to change owner
* @param string $user The new owner user name
* @param bool $recursive Whether change the owner recursively or not
*
* @throws ehough_filesystem_exception_IOException When the change fail
*/
public function chown($files, $user, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
$this->chown(new ehough_filesystem_iterator_SkipDotsRecursiveDirectoryIterator($file), $user, true);
} else {
$this->chown(new FilesystemIterator($file), $user, true);
}
}
if (is_link($file) && function_exists('lchown')) {
if (true !== @lchown($file, $user)) {
throw new ehough_filesystem_exception_IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
}
} else {
if (true !== @chown($file, $user)) {
throw new ehough_filesystem_exception_IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
}
}
}
}
示例12: lchown
<?php
/* Prototype : bool lchown (string filename, mixed user)
* Description: Change file owner of a symlink
* Source code: ext/standard/filestat.c
* Alias to functions:
*/
echo "*** Testing lchown() : error functionality ***\n";
// Set up
$filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lchown.txt';
touch($filename);
$uid = posix_getuid();
// Less than expected arguments
var_dump(lchown($filename));
// More than expected arguments
var_dump(lchown($filename, $uid, 'foobar'));
// Non-existent filename
var_dump(lchown('foobar_lchown.txt', $uid));
// Wrong argument types
var_dump(lchown(new StdClass(), $uid));
var_dump(lchown(array(), $uid));
// Bad user
var_dump(lchown($filename, -5));
?>
===DONE===
示例13: url_stat
{
return true;
}
public function url_stat($path, $flags)
{
return true;
}
}
stream_wrapper_register("abc", "A") or die("Failed to register protocol");
touch('abc://a');
touch('abc://b', 15);
touch('abc://c', 15, 25);
chmod('abc://d', 0123);
chmod('abc://e', 0345);
chown('abc://f', 0);
chown('abc://g', 10);
chown('abc://h', 'root');
lchown('abc://i', 0);
lchown('abc://j', 10);
lchown('abc://k', 'root');
chgrp('abc://l', 0);
chgrp('abc://m', 10);
chgrp('abc://n', 'root');
lchgrp('abc://o', 0);
lchgrp('abc://p', 10);
lchgrp('abc://q', 'root');
// explicit errors
chown('abc://r', []);
lchown('abc://s', []);
chgrp('abc://t', []);
lchgrp('abc://u', []);
示例14: tempnam
<?php
$file = tempnam('/tmp', 'lchown');
$link = tempnam('/tmp', 'lchown');
touch($file);
@symlink($file, $link);
var_dump(lchown($link, 'ihopenomachinehasthisuserthatwouldbebad'));
var_dump(chown($file, 'ihopenomachinehasthisuserthatwouldbebad'));
示例15: lchgrp
function lchgrp($fn, $group)
{
return lchown($fn, ":{$group}");
}