xref: /PHP-5.6/ext/standard/tests/file/006_basic.phpt (revision 69fbaf7d)
1--TEST--
2Test fileperms() & chmod() functions: basic functionality
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip Not on Windows');
7}
8// Skip if being run by root
9$filename = dirname(__FILE__)."/006_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');
15}
16
17unlink($filename);
18
19?>
20--FILE--
21<?php
22/*
23  Prototype: int fileperms ( string $filename );
24  Description: Returns the permissions on the file, or FALSE in case of an error
25
26  Prototype: bool chmod ( string $filename, int $mode );
27  Description: Attempts to change the mode of the file specified by
28    filename to that given in mode
29*/
30$path = dirname(__FILE__);
31
32echo "*** Testing fileperms(), chmod() with files and dirs ***\n";
33fopen($path."/perm.tmp", "w");
34var_dump( chmod($path."/perm.tmp", 0755 ) );
35printf("%o", fileperms($path."/perm.tmp") );
36echo "\n";
37clearstatcache();
38
39mkdir($path."/perm");
40var_dump( chmod( $path."/perm", 0777 ) );
41printf("%o", fileperms($path."/perm") );
42echo "\n";
43clearstatcache();
44
45echo "Done\n";
46?>
47--CLEAN--
48<?php
49unlink(dirname(__FILE__)."/perm.tmp");
50rmdir(dirname(__FILE__)."/perm");
51?>
52--EXPECTF--
53*** Testing fileperms(), chmod() with files and dirs ***
54bool(true)
55100755
56bool(true)
5740777
58Done
59