1--TEST--
2Test unlink() function : usage variations - unlinking file in a directory
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip only on Linux');
7}
8require __DIR__ . '/../skipif_root.inc';
9?>
10--FILE--
11<?php
12
13/* Delete file having default permission but its dir having readonly permission
14   Delete file having readonly permission but dir having default permission
15*/
16
17
18$file_path = __DIR__;
19
20// temp dir name used here
21$dirname = "$file_path/unlink_variation1";
22// temp filename used here
23$filename = "$dirname/unlink_variation1.tmp";
24
25echo "\n*** Testing unlink() on file inside a directory ***\n";
26// create temp dir
27mkdir($dirname);
28// create temp file inside $dirname
29$fp = fopen($filename, "w");
30fclose($fp);
31
32echo "-- Unlink file having default permission and its dir having read only permission --\n";
33// remove write permission of $dirname
34var_dump( chmod($dirname, 0444) );
35// now try deleting $filename
36var_dump( unlink($filename) );  // expected false
37var_dump( file_exists($filename) );  // confirm file is deleted
38
39// remove the dir
40var_dump( chmod($dirname, 0777) );
41var_dump( unlink($filename) );  // expected true
42var_dump( rmdir($dirname) );
43
44echo "\n-- Unlinking file without write permission, its dir having default permission --\n";
45// create the temp dir
46var_dump( mkdir($dirname) );
47// create the temp file
48$fp = fopen($filename, "w");
49fclose($fp);
50
51// remove write permission from file
52var_dump( chmod($filename, 0444) );
53// now try deleting temp file inside $dirname
54var_dump( unlink($filename) );  // expected: true
55var_dump( file_exists($filename) );  // expected: false
56
57// remove temp dir
58var_dump( rmdir($dirname) );
59
60echo "Done\n";
61?>
62--EXPECTF--
63*** Testing unlink() on file inside a directory ***
64-- Unlink file having default permission and its dir having read only permission --
65bool(true)
66
67Warning: unlink(%s): %s in %s on line %d
68bool(false)
69bool(false)
70bool(true)
71bool(true)
72bool(true)
73
74-- Unlinking file without write permission, its dir having default permission --
75bool(true)
76bool(true)
77bool(true)
78bool(false)
79bool(true)
80Done
81