Current Location: Home> Function Categories> lchown

lchown

Modify the owner of the symbolic link
Name:lchown
Category:File system
Programming Language:php
One-line Description:Change the owner of the specified file

Function name: lchown()

Applicable version: PHP 4, PHP 5, PHP 7

Function description: The lchown() function is used to change the owner of the specified file. Unlike the chown() function, the lchown() function can handle symbolic link files.

Syntax: bool lchown ( string $filename , mixed $user )

parameter:

  • filename: To change the file path of the owner.
  • user: new owner. It can be a username or user ID.

Return value:

  • Return true if the owner is successfully changed.
  • If an error occurs, false is returned.

Example:

 // 示例一:将文件的所有者更改为新用户$filename = '/path/to/file.txt'; $user = 'newuser'; if (lchown($filename, $user)) { echo "文件所有者已成功更改为{$user}。"; } else { echo "无法更改文件所有者。"; } // 示例二:将文件的所有者更改为新用户的用户ID $filename = '/path/to/file.txt'; $user = 1001; if (lchown($filename, $user)) { echo "文件所有者已成功更改为用户ID {$user}。"; } else { echo "无法更改文件所有者。"; }

Notes:

  • The lchown() function can only run on an operating system with sufficient permissions, otherwise it will return false.
  • This function can only change the owner of the file, and cannot change the group to which the file belongs. To change the group to which the file belongs, use the lchgrp() function.
  • If the specified file is a symbolic link and the operating system does not support changing the owner of the symbolic link file, the function returns false.
Similar Functions
Popular Articles