|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-08-31 17:05 UTC] rdueck at mcmillan-mcgee dot com
Description:
------------
When running from Apache2 using apache-mod-php, rename() strips extended attributes. The same code works from the command line, and the system 'mv' command works in both cases.
move_uploaded_file() has the same problem as rename().
Test script:
---------------
<?php
// Requires xattr:
// pecl install xattr
// then add 'extension=xattr.so' to php.ini
// ASSUME: current directory is not /tmp
$a = tempnam('/tmp','my');
$b = basename($a);
for ($i=0; $i<2; $i++) {
file_put_contents($a,'TestData');
xattr_set($a,'owner','me');
switch($i){
case 0: rename($a,$b); $fn='rename'; break;
case 1: `mv $a $b`; $fn='mv'; break;
}
$owner = xattr_get($b,'owner');
echo "$fn ".($owner=='me'?'SUCCEEDED':'FAILED')."\n";
}
Expected result:
----------------
rename SUCCEEDED
mv SUCCEEDED
Actual result:
--------------
rename FAILED
mv SUCCEEDED
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
I added an inode check and confirmed that both rename() and 'mv' are being performed as copy-and-delete when run from apache. 'mv' preserves extended attributes when copying, but rename() does not. Test script: <?php // Requires xattr: // pecl install xattr // then add 'extension=xattr.so' to php.ini // ASSUME: current directory is not /tmp $a = tempnam('/tmp','my'); $b = basename($a); for ($i=0; $i<2; $i++) { file_put_contents($a,'TestData'); $inode_a = stat($a)['ino']; xattr_set($a,'owner','me'); switch($i){ case 0: rename($a,$b); $fn='rename'; break; case 1: `mv $a $b`; $fn='mv'; break; } $inode_b = stat($b)['ino']; $owner = xattr_get($b,'owner'); echo "$fn ".($owner=='me'?'SUCCEEDED':'FAILED').", internal operation: ".($inode_a==$inode_b?'move':'copy')."\n"; }