Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Here's a little test to figure out how PHP handles this whole chmod
- * situation. We try both string values and plain int values to set the
- * access controls.
- *
- * It turns out that mkdir does not respect the sticky bit. An extra chmod is
- * needed to add it. Not even ignoring the umask helps. Is this a PHP bug?
- */
- $testPath = '/Users/michiel/wb/WebRoot/6.2.master.workbench.local/fileadmin/test/';
- $tests = array(
- 'string' => array(
- 'file' => octdec('0664'),
- 'directory' => octdec('02775')
- ),
- 'integer' => array(
- 'file' => 0664,
- 'directory' => 02775
- )
- );
- $expected = array(
- 'file' => '100664',
- 'directory' => '42775'
- );
- var_dump($tests);
- foreach ($tests as $type => $testData) {
- echo '<h3>' . $type . ' Mode test</h3><br/>';
- foreach ($testData as $nodeType => $mode) {
- echo 'Mode test using ' . $nodeType . '. Outcome should be ' . $expected[$nodeType] . '<br/>';
- if ($nodeType === 'file') {
- echo 'Plain chmod.<br/>';
- $nodename = $testPath . $type . '-' . $nodeType . '-plain.txt';
- file_put_contents($nodename, 'lala');
- chmod($nodename, $mode);
- var_dump(decoct(fileperms($nodename)));
- } else {
- echo 'Plain mkdir.<br/>';
- $nodename = $testPath . $type . '-' . $nodeType . '-plain';
- mkdir($nodename, $mode);
- var_dump(decoct(fileperms($nodename)));
- echo 'Using mkdir and extra chmod.<br/>';
- $nodename = $testPath . $type . '-' . $nodeType . '-extra-chmod';
- mkdir($nodename, $mode);
- chmod($nodename, $mode);
- var_dump(decoct(fileperms($nodename)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement