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 11/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); 12 Description: Renames a file or directory 13*/ 14 15require dirname(__FILE__).'/file.inc'; 16 17/* creating directory */ 18$file_path = dirname(__FILE__); 19$dirname = "$file_path/rename_variation3_dir"; 20mkdir($dirname); 21 22/* test rename() by trying to rename an existing file/dir to the same name 23 and one another */ 24 25$filename = "$file_path/rename_variation3.tmp"; 26$fp = fopen($filename, "w"); 27if (!$fp) { 28 die("Cannot create $filename\n"); 29} 30fclose($fp); 31 32echo "\n-- Renaming file to same file name --\n"; 33var_dump( rename($filename, $filename) ); 34var_dump( file_exists($filename) ); 35 36echo "\n-- Renaming directory to same directory name --\n"; 37var_dump( rename($dirname, $dirname) ); 38var_dump( file_exists($dirname) ); 39 40echo "\n-- Renaming existing file to existing directory name --\n"; 41var_dump( rename($filename, $dirname) ); 42var_dump( file_exists($filename) ); 43var_dump( file_exists($dirname) ); 44 45echo "\n-- Renaming existing directory to existing file name --\n"; 46$fp = fopen($filename, "w"); 47fclose($fp); 48 49var_dump( rename($dirname, $filename) ); 50var_dump( file_exists($filename) ); 51var_dump( file_exists($dirname) ); 52 53echo "Done\n"; 54?> 55--CLEAN-- 56<?php 57$file_path = dirname(__FILE__); 58unlink($file_path."/rename_variation3_link.tmp"); 59unlink($file_path."/rename_variation3.tmp"); 60rmdir($file_path."/rename_variation3_dir"); 61rmdir($file_path."/rename_variation3.tmp"); 62?> 63--EXPECTF-- 64-- Renaming file to same file name -- 65bool(true) 66bool(true) 67 68-- Renaming directory to same directory name -- 69bool(true) 70bool(true) 71 72-- Renaming existing file to existing directory name -- 73 74Warning: rename(%s/rename_variation3.tmp,%s/rename_variation3_dir): Access is denied. (code: 5) in %s on line %d 75bool(false) 76bool(true) 77bool(true) 78 79-- Renaming existing directory to existing file name -- 80bool(true) 81bool(true) 82bool(false) 83Done 84 85