1--TEST-- 2Test fileatime(), filemtime(), filectime() & touch() functions : usage variation 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if (substr(PHP_OS, 0, 3) != 'WIN') { 8 die('skip.. only for Windows'); 9} 10?> 11--FILE-- 12<?php 13/* 14 Prototype: int fileatime ( string $filename ); 15 Description: Returns the time the file was last accessed, or FALSE 16 in case of an error. The time is returned as a Unix timestamp. 17 18 Prototype: int filemtime ( string $filename ); 19 Description: Returns the time the file was last modified, or FALSE 20 in case of an error. 21 22 Prototype: int filectime ( string $filename ); 23 Description: Returns the time the file was last changed, or FALSE 24 in case of an error. The time is returned as a Unix timestamp. 25 26 Prototype: bool touch ( string $filename [, int $time [, int $atime]] ); 27 Description: Attempts to set the access and modification times of the file 28 named in the filename parameter to the value given in time. 29*/ 30 31/* 32 Prototype: void stat_fn(string $filename); 33 Description: Prints access, modification and change times of a file 34*/ 35function stat_fn( $filename ) { 36 echo "\n-- File '$filename' --\n"; 37 echo "-- File access time is => "; 38 echo fileatime($filename)."\n"; 39 clearstatcache(); 40 echo "-- File modification time is => "; 41 echo filemtime($filename)."\n"; 42 clearstatcache(); 43 echo "-- inode change time is => "; 44 echo filectime($filename)."\n"; 45 clearstatcache(); 46 47 48} 49 50echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n"; 51echo "\n*** testing file info ***"; 52stat_fn(NULL); 53stat_fn(false); 54stat_fn(''); 55stat_fn(' '); 56stat_fn('|'); 57echo "\n*** testing touch ***"; 58var_dump(touch(NULL)); 59var_dump(touch(false)); 60var_dump(touch('')); 61 62//php generates permission denied, we generate No such file or dir. 63var_dump(touch(' ')); 64var_dump(touch('|')); 65 66 67echo "Done"; 68?> 69--EXPECTF-- 70*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations *** 71 72*** testing file info *** 73-- File '' -- 74-- File access time is => 75-- File modification time is => 76-- inode change time is => 77 78-- File '' -- 79-- File access time is => 80-- File modification time is => 81-- inode change time is => 82 83-- File '' -- 84-- File access time is => 85-- File modification time is => 86-- inode change time is => 87 88-- File ' ' -- 89-- File access time is => 90Warning: fileatime(): stat failed for in %s on line %d 91 92-- File modification time is => 93Warning: filemtime(): stat failed for in %s on line %d 94 95-- inode change time is => 96Warning: filectime(): stat failed for in %s on line %d 97 98 99-- File '|' -- 100-- File access time is => 101Warning: fileatime(): stat failed for | in %s on line %d 102 103-- File modification time is => 104Warning: filemtime(): stat failed for | in %s on line %d 105 106-- inode change time is => 107Warning: filectime(): stat failed for | in %s on line %d 108 109 110*** testing touch *** 111Warning: touch(): %s in %s on line %d 112bool(false) 113 114Warning: touch(): %s in %s on line %d 115bool(false) 116 117Warning: touch(): %s in %s on line %d 118bool(false) 119 120Warning: touch(): %s in %s on line %d 121bool(false) 122 123Warning: touch(): %s in %s on line %d 124bool(false) 125Done 126