PHP中的chown()函数是一个内置函数,用于更改指定文件的所有者。成功时返回true,失败时返回false。只有超级用户有权更改文件的所有者。
null
语法:
bool chown ( $filename, $user )
参数: PHP中的chown()函数接受两个参数,即filename和user。
- $filename :指定要更改其所有者的文件。
- $user :它指定新的所有者。它可以是用户名或用户id。
返回值: 函数的作用是:成功时返回true,失败时返回false。
错误和例外 :
- PHP中的chown()函数不适用于远程文件。它只适用于服务器文件系统可以访问的文件。
- 启用安全模式时,PHP检查正在操作的文件或目录是否与正在执行的脚本拥有相同的所有者。
例如:
Input : chown("gfg.txt", "shubrodeep") Output : true Input : $path = "/user01/Desktop/geeksforgeeks/gfg.php"; $user_name = "root"; chown($path, $user_name); Output : true
下面的程序演示了chown()函数。
方案1 :
<?php // Sets shubrodeep as owner chown ( "gfg.txt" , "shubrodeep" ); ?> |
输出:
true
方案2 :
<?php // Sets root as owner of the file "gfg.php" $path = "/user01/Desktop/geeksforgeeks/gfg.php" ; $user_name = "root" ; chown ( $path , $user_name ); ?> |
输出:
true
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END