1--TEST-- 2Test rename() function: usage variations 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) != 'WIN') { 6 die('skip.. only for Windows'); 7} 8?> 9--FILE-- 10<?php 11require __DIR__.'/file.inc'; 12 13/* create directory */ 14$file_path = __DIR__; 15mkdir("$file_path/rename_variation"); 16 17/* rename files across directories */ 18echo "*** Testing rename() : rename files across directories ***\n"; 19$src_filenames = array( 20 "$file_path/rename_variation/rename_variation.tmp", 21 22 /* Testing a file trailing slash */ 23 "$file_path/rename_variation/rename_variation.tmp/", 24 25 /* Testing file with double slashes */ 26 "$file_path/rename_variation//rename_variation.tmp", 27 "$file_path//rename_variation//rename_variation.tmp", 28); 29 30$counter = 1; 31 32/* loop through each $file and rename it to rename_variation2.tmp */ 33foreach($src_filenames as $src_filename) { 34 echo "-- Iteration $counter --\n"; 35 $fp = fopen("$file_path/rename_variation/rename_variation.tmp", "w"); 36 fclose($fp); 37 $dest_filename = "$file_path/rename_variation2.tmp"; 38 var_dump( rename($src_filename, $dest_filename) ); 39 40 // ensure that file got renamed to new name 41 var_dump( file_exists($src_filename) ); // expecting false 42 var_dump( file_exists($dest_filename) ); // expecting true 43 $counter++; 44 45 // unlink the file 46 unlink($dest_filename); 47} 48 49rmdir("$file_path/rename_variation"); 50 51echo "Done\n"; 52?> 53--CLEAN-- 54<?php 55$file_path = __DIR__; 56unlink($file_path."/rename_variation_link.tmp"); 57unlink($file_path."/rename_variation.tmp"); 58rmdir($file_path."/rename_variation_dir"); 59?> 60--EXPECTF-- 61*** Testing rename() : rename files across directories *** 62-- Iteration 1 -- 63bool(true) 64bool(false) 65bool(true) 66-- Iteration 2 -- 67 68Warning: rename(%s/rename_variation/rename_variation.tmp/,%s/rename_variation2.tmp): The filename, directory name, or volume label syntax is incorrect (code: 123) in %s on line %d 69bool(false) 70bool(false) 71bool(false) 72 73Warning: unlink(%s/rename_variation2.tmp): No such file or directory in %s on line %d 74-- Iteration 3 -- 75bool(true) 76bool(false) 77bool(true) 78-- Iteration 4 -- 79bool(true) 80bool(false) 81bool(true) 82Done 83