Exemplo n.º 1
0
   Prototype: void stat_fn(string $filename);
   Description: Prints access, modification and change times of a file
*/
function stat_fn($filename)
{
    echo "\n-- File '{$filename}' --\n";
    echo "-- File access time is => ";
    echo fileatime($filename) . "\n";
    clearstatcache();
    echo "-- File modification time is => ";
    echo filemtime($filename) . "\n";
    clearstatcache();
    echo "-- inode change time is => ";
    echo filectime($filename) . "\n";
    clearstatcache();
}
echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n";
echo "\n*** testing file info ***";
stat_fn(NULL);
stat_fn(false);
stat_fn('');
stat_fn(' ');
stat_fn('|');
echo "\n*** testing touch ***";
var_dump(touch(NULL));
var_dump(touch(false));
var_dump(touch(''));
//php generates permission denied, we generate No such file or dir.
var_dump(touch(' '));
var_dump(touch('|'));
echo "Done";
echo "\n-- Checking different times, after performing is_file() operation on the file --\n";
is_file($file_name);
stat_fn($file_name);
sleep(2);
echo "\n*** Testing touch() function with different time values ***\n";
$file_name2 = $file_path . "/005_variation_touch.tmp";
$file_handle = fopen($file_name2, "w");
fclose($file_handle);
sleep(2);
/* Time is not mentioned */
var_dump(touch($file_name2));
//set to current system time
stat_fn($file_name2);
sleep(2);
/* set to access(creation time of the file) time */
var_dump(touch($file_name2, @date(fileatime($file_name2))));
stat_fn($file_name2);
sleep(2);
/* set to access time of $file_name2 */
var_dump(touch($file_path . "/005_variation_touch_fly.tmp", @date(fileatime($file_name2)), time()));
stat_fn($file_name2);
sleep(2);
/* set to default value, with Invalid timestamps */
var_dump(touch($file_name2, 10));
stat_fn($file_name2);
var_dump(touch($file_name2, 10, 20));
stat_fn($file_name2);
/* touch() after renaming the file */
rename($file_name2, "{$file_path}/005_variation_touch_new.tmp");
stat_fn("{$file_path}/005_variation_touch_new.tmp");
echo "Done\n";