1--TEST-- 2chmod() with various paths 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip non-windows only test'); 7} 8?> 9--FILE-- 10<?php 11 12define("PERMISSIONS_MASK", 0777); 13 14$script_directory = dirname(__FILE__); 15chdir($script_directory); 16$test_dirname = basename(__FILE__, ".php") . "testdir"; 17mkdir($test_dirname); 18 19$filepath = __FILE__ . ".tmp"; 20$filename = basename($filepath); 21$fd = fopen($filepath, "w+"); 22fclose($fd); 23 24echo "chmod() on a path containing .. and .\n"; 25var_dump(chmod("./$test_dirname/../$filename", 0777)); 26var_dump(chmod("./$test_dirname/../$filename", 0755)); 27clearstatcache(); 28printf("%o\n", fileperms($filepath) & PERMISSIONS_MASK); 29 30echo "\nchmod() on a path containing .. with invalid directories\n"; 31var_dump(chmod($filepath, 0777)); 32var_dump(chmod("./$test_dirname/bad_dir/../../$filename", 0755)); 33clearstatcache(); 34printf("%o\n", fileperms($filepath) & PERMISSIONS_MASK); 35 36echo "\nchmod() on a linked file\n"; 37$linkname = "somelink"; 38var_dump(symlink($filepath, $linkname)); 39var_dump(chmod($filepath, 0777)); 40var_dump(chmod($linkname, 0755)); 41clearstatcache(); 42printf("%o\n", fileperms($filepath) & PERMISSIONS_MASK); 43var_dump(unlink($linkname)); 44 45echo "\nchmod() on a relative path from a different working directory\n"; 46chdir($test_dirname); 47var_dump(chmod("../$filename", 0777)); 48var_dump(chmod("../$filename", 0755)); 49clearstatcache(); 50printf("%o\n", fileperms($filepath) & PERMISSIONS_MASK); 51chdir($script_directory); 52 53echo "\nchmod() on a directory with a trailing /\n"; 54var_dump(chmod($test_dirname, 0777)); 55var_dump(chmod("$test_dirname/", 0775)); 56clearstatcache(); 57printf("%o\n", fileperms($filepath) & PERMISSIONS_MASK); 58 59chdir($script_directory); 60rmdir($test_dirname); 61unlink($filepath); 62 63?> 64--EXPECTF-- 65chmod() on a path containing .. and . 66bool(true) 67bool(true) 68755 69 70chmod() on a path containing .. with invalid directories 71bool(true) 72 73Warning: chmod(): No such file or directory in %s on line %d 74bool(false) 75777 76 77chmod() on a linked file 78bool(true) 79bool(true) 80bool(true) 81755 82bool(true) 83 84chmod() on a relative path from a different working directory 85bool(true) 86bool(true) 87755 88 89chmod() on a directory with a trailing / 90bool(true) 91bool(true) 92755 93