1--TEST-- 2Test rename() function: basic functionality 3--FILE-- 4<?php 5/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); 6 Description: Renames a file or directory 7*/ 8 9echo "\n*** Testing rename() by giving stream context as third argument ***\n"; 10$file_path = dirname(__FILE__); 11 12$context = stream_context_create(); 13 14// on directory 15$dir_name = "$file_path/rename_variation_dir9"; 16$new_dir_name = "$file_path/rename_variation_dir9_new"; 17 18mkdir($dir_name); 19 20var_dump( rename($dir_name, $new_dir_name, $context) ); 21var_dump( file_exists($dir_name) ); // expecting flase 22var_dump( file_exists($new_dir_name) ); // expecting true 23 24//on file 25$src_name = "$file_path/rename_variation9.tmp"; 26$dest_name = "$file_path/rename_variation9_new.tmp"; 27 28// create the file 29$fp = fopen($src_name, "w"); 30$s1 = stat($src_name); 31fclose($fp); 32 33var_dump( rename($src_name, $dest_name, $context) ); 34var_dump( file_exists($src_name) ); // expecting false 35var_dump( file_exists($dest_name) ); // expecting true 36 37echo "Done\n"; 38?> 39--CLEAN-- 40<?php 41unlink(dirname(__FILE__)."/rename_variation9_new.tmp"); 42rmdir(dirname(__FILE__)."/rename_variation_dir9_new"); 43?> 44--EXPECT-- 45*** Testing rename() by giving stream context as third argument *** 46bool(true) 47bool(false) 48bool(true) 49bool(true) 50bool(false) 51bool(true) 52Done 53 54