1--TEST-- 2Test rename() function : variation - various relative, absolute paths 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if (substr(PHP_OS, 0, 3) != 'WIN') die('skip.. for Windows'); 8?> 9--FILE-- 10<?php 11/* Creating unique files in various dirs by passing relative paths to $dir arg */ 12 13echo "*** Testing rename() with absolute and relative paths ***\n"; 14$mainDir = "renameVar12"; 15$subDir = "renameVar12Sub"; 16$absMainDir = __DIR__."/".$mainDir; 17mkdir($absMainDir); 18$absSubDir = $absMainDir."/".$subDir; 19mkdir($absSubDir); 20 21$fromFile = "renameMe.tmp"; 22$toFile = "IwasRenamed.tmp"; 23 24$old_dir_path = getcwd(); 25chdir(__DIR__); 26 27$allDirs = array( 28 // absolute paths 29 "$absSubDir/", 30 "$absSubDir/../".$subDir, 31 "$absSubDir//.././".$subDir, 32 "$absSubDir/../../".$mainDir."/./".$subDir, 33 "$absSubDir/..///".$subDir."//..//../".$subDir, 34 "$absSubDir/BADDIR", 35 36 37 // relative paths 38 $mainDir."/".$subDir, 39 $mainDir."//".$subDir, 40 $mainDir."///".$subDir, 41 "./".$mainDir."/../".$mainDir."/".$subDir, 42 "BADDIR", 43); 44 45for($i = 0; $i<count($allDirs); $i++) { 46 $j = $i+1; 47 $dir = $allDirs[$i]; 48 echo "\n-- Iteration $j --\n"; 49 touch($absSubDir."/".$fromFile); 50 $res = rename($dir."/".$fromFile, $dir."/".$toFile); 51 var_dump($res); 52 if ($res == true) { 53 $res = rename($dir."/".$toFile, $dir."/".$fromFile); 54 var_dump($res); 55 } 56 unlink($absSubDir."/".$fromFile); 57} 58 59chdir($old_dir_path); 60rmdir($absSubDir); 61rmdir($absMainDir); 62 63echo "\n*** Done ***\n"; 64?> 65--EXPECTF-- 66*** Testing rename() with absolute and relative paths *** 67 68-- Iteration 1 -- 69bool(true) 70bool(true) 71 72-- Iteration 2 -- 73bool(true) 74bool(true) 75 76-- Iteration 3 -- 77bool(true) 78bool(true) 79 80-- Iteration 4 -- 81bool(true) 82bool(true) 83 84-- Iteration 5 -- 85 86Warning: rename(%s/renameVar12/renameVar12Sub/..///renameVar12Sub//..//../renameVar12Sub/renameMe.tmp,%s/renameVar12/renameVar12Sub/..///renameVar12Sub//..//../renameVar12Sub/IwasRenamed.tmp): The system cannot find the path specified (code: 3) in %s on line %d 87bool(false) 88 89-- Iteration 6 -- 90 91Warning: rename(%s/renameVar12/renameVar12Sub/BADDIR/renameMe.tmp,%s/renameVar12/renameVar12Sub/BADDIR/IwasRenamed.tmp): The system cannot find the path specified (code: 3) in %s on line %d 92bool(false) 93 94-- Iteration 7 -- 95bool(true) 96bool(true) 97 98-- Iteration 8 -- 99bool(true) 100bool(true) 101 102-- Iteration 9 -- 103bool(true) 104bool(true) 105 106-- Iteration 10 -- 107bool(true) 108bool(true) 109 110-- Iteration 11 -- 111 112Warning: rename(BADDIR/renameMe.tmp,BADDIR/IwasRenamed.tmp): The system cannot find the path specified (code: 3) in %s on line %d 113bool(false) 114 115*** Done *** 116