1--TEST-- 2Test scandir() function : usage variations - different directory permissions 3--SKIPIF-- 4<?php 5if( substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip Not for Windows'); 7} 8// Skip if being run by root (files are always readable, writeable and executable) 9$filename = dirname(__FILE__)."/dir_root_check.tmp"; 10$fp = fopen($filename, 'w'); 11fclose($fp); 12if(fileowner($filename) == 0) { 13 unlink ($filename); 14 die('skip...cannot be run as root\n'); 15} 16unlink($filename); 17?> 18--FILE-- 19<?php 20/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) 21 * Description: List files & directories inside the specified path 22 * Source code: ext/standard/dir.c 23 */ 24 25/* 26 * remove the execute permission from the parent dir and test scandir() on child dir 27 * 1. remove write & execute permission from the 1st parent and test scandir() 28 * 2. remove execute permission from 2nd parent and test scandir() 29 */ 30 31echo "*** Testing scandir() : usage variations ***\n"; 32 33/* 34 * create the temporary directory : 35 * scandir_variation5 ( parent ) 36 * |-> sub_dir ( sub parent ) 37 * |-> child_dir ( child dir) 38 */ 39 40$parent_dir_path = dirname(__FILE__) . "/scandir_variation5"; 41mkdir($parent_dir_path); 42chmod($parent_dir_path, 0777); 43 44// create sub_dir 45$sub_dir_path = $parent_dir_path . "/sub_dir"; 46mkdir($sub_dir_path); 47chmod($sub_dir_path, 0777); 48 49//create sub_sub_dir 50$child_dir_path = $sub_dir_path."/child_dir"; 51mkdir($child_dir_path); 52 53// remove the write and execute permisson from sub parent 54chmod($sub_dir_path, 0444); 55 56echo "\n-- After restricting 1st level parent directory --\n"; 57var_dump(scandir($child_dir_path)); 58 59// remove the execute permisson from parent dir, allowing all permission for sub dir 60chmod($sub_dir_path, 0777); // all permisson to sub dir 61chmod($parent_dir_path, 0666); // restricting parent directory 62 63echo "\n-- After restricting parent directory --\n"; 64var_dump(scandir($child_dir_path)); 65?> 66===DONE=== 67--CLEAN-- 68<?php 69$parent_dir_path = dirname(__FILE__) . "/scandir_variation5"; 70$sub_dir_path = $parent_dir_path."/sub_dir"; 71$child_dir_path = $sub_dir_path."/child_dir"; 72 73// changing permissions for each temporary directory to delete them 74chmod($parent_dir_path, 0777); 75chmod($sub_dir_path, 0777); 76chmod($child_dir_path, 0777); 77 78rmdir($child_dir_path); 79rmdir($sub_dir_path); 80rmdir($parent_dir_path); 81?> 82--EXPECTF-- 83*** Testing scandir() : usage variations *** 84 85-- After restricting 1st level parent directory -- 86 87Warning: scandir(%s/scandir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d 88 89Warning: scandir(): (errno %d): %s in %s on line %d 90bool(false) 91 92-- After restricting parent directory -- 93 94Warning: scandir(%s/scandir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d 95 96Warning: scandir(): (errno %d): %s in %s on line %d 97bool(false) 98===DONE=== 99