1--TEST-- 2Test unlink() function : variation: various valid and invalid paths 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if (substr(PHP_OS, 0, 3) != 'WIN') { 8 die('skip.. only for Windows'); 9} 10?> 11--FILE-- 12<?php 13echo "*** Testing unlink() : variation ***\n"; 14 15$workDir = "unlinkVar9.tmp"; 16$tmpFile = "file.tmp"; 17chdir(__DIR__); 18mkdir($workDir); 19$cwd = __DIR__; 20$unixifiedFile = '/'.substr(str_replace('\\','/',$cwd).'/'.$workDir.'/'.$tmpFile, 3); 21 22$files = array( 23 // relative 24 $workDir.'\\'.$tmpFile, 25 '.\\'.$workDir.'\\'.$tmpFile, 26 $workDir.'\\..\\'.$workDir.'\\'.$tmpFile, 27 28 // relative bad path 29 $workDir.'\\..\\BADDIR\\'.$tmpFile, 30 'BADDIR\\'.$tmpFile, 31 32 //absolute 33 $cwd.'\\'.$workDir.'\\'.$tmpFile, 34 $cwd.'\\.\\'.$workDir.'\\'.$tmpFile, 35 $cwd.'\\'.$workDir.'\\..\\'.$workDir.'\\'.$tmpFile, 36 37 //absolute bad path 38 $cwd.'\\BADDIR\\'.$tmpFile, 39 40 //trailing separators 41 $workDir.'\\'.$tmpFile.'\\', 42 $cwd.'\\'.$workDir.'\\'.$tmpFile.'\\', 43 44 // multiple separators 45 $workDir.'\\\\'.$tmpFile, 46 $cwd.'\\\\'.$workDir.'\\\\'.$tmpFile, 47 48 // Unixified File 49 $unixifiedFile, 50 51 ); 52 53 54foreach($files as $fileToUnlink) { 55 $file = $workDir.'/'.$tmpFile; 56 $tounlink = $fileToUnlink; 57 touch($file); 58 echo "-- removing $tounlink --\n"; 59 $res = unlink($tounlink); 60 if ($res === true) { 61 if (file_exists($tounlink) === false) { 62 echo "file removed\n"; 63 } 64 else { 65 echo "FAILED: file not removed\n"; 66 } 67 } 68 else { 69 unlink($file); 70 } 71} 72 73rmdir($workDir); 74?> 75--EXPECTF-- 76*** Testing unlink() : variation *** 77-- removing unlinkVar9.tmp\file.tmp -- 78file removed 79-- removing .\unlinkVar9.tmp\file.tmp -- 80file removed 81-- removing unlinkVar9.tmp\..\unlinkVar9.tmp\file.tmp -- 82file removed 83-- removing unlinkVar9.tmp\..\BADDIR\file.tmp -- 84 85Warning: unlink(unlinkVar9.tmp\..\BADDIR\file.tmp): No such file or directory in %s on line %d 86-- removing BADDIR\file.tmp -- 87 88Warning: unlink(BADDIR\file.tmp): No such file or directory in %s on line %d 89-- removing %s\unlinkVar9.tmp\file.tmp -- 90file removed 91-- removing %s\.\unlinkVar9.tmp\file.tmp -- 92file removed 93-- removing %s\unlinkVar9.tmp\..\unlinkVar9.tmp\file.tmp -- 94file removed 95-- removing %s\BADDIR\file.tmp -- 96 97Warning: unlink(%s\BADDIR\file.tmp): No such file or directory in %s on line %d 98-- removing unlinkVar9.tmp\file.tmp\ -- 99 100Warning: unlink(unlinkVar9.tmp\file.tmp\): No such file or directory in %s on line %d 101-- removing %s\unlinkVar9.tmp\file.tmp\ -- 102 103Warning: unlink(%s\unlinkVar9.tmp\file.tmp\): No such file or directory in %s on line %d 104-- removing unlinkVar9.tmp\\file.tmp -- 105file removed 106-- removing %s\\unlinkVar9.tmp\\file.tmp -- 107file removed 108-- removing /%s/unlinkVar9.tmp/file.tmp -- 109file removed 110