|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-09-19 19:51 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 10:00:01 2025 UTC |
Description: ------------ There is no way to change the owner or group of a symlink. Using chown and chgrp functions on a symlink affect the file referenced by the symbolic link, rather than the symbolic link itself. There should have a "$dereference" argument to be able to affect the file referenced by the symlink or the symlink itself. Reproduce code: --------------- <?php // Setup test files if (file_exists('test-referent')) unlink('test-referent'); if (file_exists('test-symlink')||is_link('test-symlink')) unlink('test-symlink'); touch('test-referent'); symlink('test-referent', 'test-symlink'); echo shell_exec('chown -h nobody test-symlink test-referent 2>&1'); echo "Original owners: \n"; echo shell_exec("ls -l test-referent test-symlink") . "\n"; // Test changing symlink owner with PHP's chown() function chown('test-symlink', 'root'); echo "New owners: \n"; echo shell_exec("ls -l test-referent test-symlink"); ?> Expected result: ---------------- chown should affect symlink owner instead of the referenced file Original owners: -rw-r--r-- 1 nobody root 0 2007-09-19 16:04 test-referent lrwxrwxrwx 1 nobody root 13 2007-09-19 16:04 test-symlink -> test-referent New owners: -rw-r--r-- 1 nobody root 0 2007-09-19 16:04 test-referent lrwxrwxrwx 1 root root 13 2007-09-19 16:04 test-symlink -> test-referent Actual result: -------------- chown has affected the referenced file instead of the symlink itself Original owners: -rw-r--r-- 1 nobody root 0 2007-09-19 16:04 test-referent lrwxrwxrwx 1 nobody root 13 2007-09-19 16:04 test-symlink -> test-referent New owners: -rw-r--r-- 1 root root 0 2007-09-19 16:04 test-referent lrwxrwxrwx 1 nobody root 13 2007-09-19 16:04 test-symlink -> test-referent