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 Windows');
7}
8?>
9--FILE--
10<?php
11/* Prototype : bool unlink ( string $filename [, resource $context] );
12   Description : Deletes filename
13*/
14
15/* Delete file having default permission but its dir having readonly permission
16   Delete file having readonly permission but dir having default permission
17*/
18
19
20$file_path = dirname(__FILE__);
21
22// temp dir name used here
23$dirname = "$file_path/unlink_variation1";
24// temp filename used here
25$filename = "$dirname/unlink_variation1-win32.tmp";
26
27echo "\n*** Testing unlink() on file inside a directory ***\n";
28// create temp dir
29mkdir($dirname);
30// create temp file inside $dirname
31$fp = fopen($filename, "w");
32fclose($fp);
33
34echo "-- Unlink file having default permission and its dir having read only permission --\n";
35// remove write permission of $dirname
36// on windows dir permission is not respected
37var_dump( chmod($dirname, 0444) );
38// now try deleting $filename
39var_dump( unlink($filename) );  // expected: true
40var_dump( file_exists($filename) );  // confirm file is deleted
41
42// remove the dir
43var_dump( chmod($dirname, 0777) );
44rmdir($dirname);
45
46echo "\n-- Unlinking file without write permission, its dir having default permission --\n";
47// create the temp dir
48mkdir($dirname);
49
50// create the temp file
51$fp = fopen($filename, "w");
52fclose($fp);
53
54// remove write permission from file
55var_dump( chmod($filename, 0444) );
56
57// now try deleting temp file inside $dirname
58var_dump( unlink($filename) );  // expected: false
59
60// reassign write permission to temp file
61chmod($filename, 0777);
62// delete temp file
63var_dump( unlink($filename) );
64var_dump( file_exists($filename) );  // confirm file is deleted
65// remove temp dir
66rmdir($dirname);
67
68echo "Done\n";
69?>
70--EXPECTF--
71*** Testing unlink() on file inside a directory ***
72-- Unlink file having default permission and its dir having read only permission --
73bool(true)
74bool(true)
75bool(false)
76bool(true)
77
78-- Unlinking file without write permission, its dir having default permission --
79bool(true)
80
81Warning: unlink(%s/unlink_variation1/unlink_variation1-win32.tmp): Permission denied in %s on line %d
82bool(false)
83bool(true)
84bool(false)
85Done
86