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 12/* Delete file having default permission but its dir having readonly permission 13 Delete file having readonly permission but dir having default permission 14*/ 15 16 17$file_path = __DIR__.DIRECTORY_SEPARATOR."unlinkVar1私はガラスを食べられます"; 18@mkdir($file_path); 19 20// temp dir name used here 21$dirname = "$file_path/unlink_variation1"; 22// temp filename used here 23$filename = "$dirname/unlink_variation1-win32.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 34// on windows dir permission is not respected 35var_dump( chmod($dirname, 0444) ); 36// now try deleting $filename 37var_dump( unlink($filename) ); // expected: true 38var_dump( file_exists($filename) ); // confirm file is deleted 39 40// remove the dir 41var_dump( chmod($dirname, 0777) ); 42rmdir($dirname); 43 44echo "\n-- Unlinking file without write permission, its dir having default permission --\n"; 45// create the temp dir 46mkdir($dirname); 47 48// create the temp file 49$fp = fopen($filename, "w"); 50fclose($fp); 51 52// remove write permission from file 53var_dump( chmod($filename, 0444) ); 54 55// now try deleting temp file inside $dirname 56var_dump( unlink($filename) ); // expected: false 57 58// reassign write permission to temp file 59chmod($filename, 0777); 60// delete temp file 61var_dump( unlink($filename) ); 62var_dump( file_exists($filename) ); // confirm file is deleted 63// remove temp dir 64rmdir($dirname); 65rmdir($file_path); 66 67echo "Done\n"; 68?> 69--EXPECTF-- 70*** Testing unlink() on file inside a directory *** 71-- Unlink file having default permission and its dir having read only permission -- 72bool(true) 73bool(true) 74bool(false) 75bool(true) 76 77-- Unlinking file without write permission, its dir having default permission -- 78bool(true) 79 80Warning: unlink(%s/unlink_variation1/unlink_variation1-win32.tmp): Permission denied in %s on line %d 81bool(false) 82bool(true) 83bool(false) 84Done 85