1--TEST-- 2Test is_readable() function: usage variations - diff. file notations 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) != 'WIN') { 6 // Skip if being run by root (files are always readable, writeable and executable) 7 $filename = dirname(__FILE__)."/is_readable_root_check.tmp"; 8 $fp = fopen($filename, 'w'); 9 fclose($fp); 10 if(fileowner($filename) == 0) { 11 unlink ($filename); 12 die('skip cannot be run as root'); 13 } 14 unlink($filename); 15} 16?> 17--FILE-- 18<?php 19/* Prototype: bool is_readable ( string $filename ); 20 Description: Tells whether the filename is readable. 21*/ 22 23/* test is_readable() with file having different filepath notation */ 24 25require dirname(__FILE__).'/file.inc'; 26echo "*** Testing is_readable(): usage variations ***\n"; 27 28$file_path = dirname(__FILE__); 29mkdir("$file_path/is_readable_variation1"); 30 31// create a new temporary file 32$fp = fopen("$file_path/is_readable_variation1/bar.tmp", "w"); 33fclose($fp); 34 35/* array of files to be tested if they are readable by using 36 is_readable() function */ 37$files_arr = array( 38 "$file_path/is_readable_variation1/bar.tmp", 39 40 /* Testing a file trailing slash */ 41 "$file_path/is_readable_variation1/bar.tmp/", 42 43 /* Testing file with double slashes */ 44 "$file_path/is_readable_variation1//bar.tmp", 45 "$file_path//is_readable_variation1//bar.tmp", 46 "$file_path/is_readable_variation1/*.tmp", 47 "$file_path/is_readable_variation1/b*.tmp", 48 49 /* Testing Binary safe */ 50 "$file_path/is_readable_variation1".chr(0)."bar.tmp", 51 "$file_path".chr(0)."is_readable_variation1/bar.tmp", 52 "$file_path".chr(0)."is_readable_variation1/bar.tmp", 53 54 /* Testing directories */ 55 ".", // current directory, exp: bool(true) 56 "$file_path/is_readable_variation1" // temp directory, exp: bool(true) 57); 58$counter = 1; 59/* loop through to test each element in the above array 60 is a writable file */ 61foreach($files_arr as $file) { 62 echo "-- Iteration $counter --\n"; 63 var_dump( is_readable($file) ); 64 $counter++; 65 clearstatcache(); 66} 67 68echo "Done\n"; 69?> 70--CLEAN-- 71<?php 72unlink(dirname(__FILE__)."/is_readable_variation1/bar.tmp"); 73rmdir(dirname(__FILE__)."/is_readable_variation1/"); 74?> 75--EXPECTF-- 76*** Testing is_readable(): usage variations *** 77-- Iteration 1 -- 78bool(true) 79-- Iteration 2 -- 80bool(%s) 81-- Iteration 3 -- 82bool(true) 83-- Iteration 4 -- 84bool(true) 85-- Iteration 5 -- 86bool(false) 87-- Iteration 6 -- 88bool(false) 89-- Iteration 7 -- 90 91Warning: is_readable() expects parameter 1 to be a valid path, string given in %s on line %d 92NULL 93-- Iteration 8 -- 94 95Warning: is_readable() expects parameter 1 to be a valid path, string given in %s on line %d 96NULL 97-- Iteration 9 -- 98 99Warning: is_readable() expects parameter 1 to be a valid path, string given in %s on line %d 100NULL 101-- Iteration 10 -- 102bool(true) 103-- Iteration 11 -- 104bool(true) 105Done 106