PHP/File Directory/rename

Материал из Web эксперт
Перейти к: навигация, поиск

A file can be renamed with the rename() function

   <source lang="html4strict">

Its syntax is: bool rename (string oldname, string newname) <?

   $data_file = "data.txt";
   rename($data_file, $data_file.".old") or die("Could not rename $data_file");

?>

 </source>
   
  


Moving a file

   <source lang="html4strict">

<?php $old = "/tmp/today.txt"; $new = "/tmp/tomorrow.txt"; rename($old,$new) or die("couldn"t move $old to $new: $php_errormsg"); ?>

 </source>
   
  


Moving Files with rename( )

   <source lang="html4strict">

<?

   $filename = "data.txt";
   $filename2 = $filename . ".old";
   $result = rename($filename, $filename2);
   if ($result) {
           print "$filename has been renamed to $filename2.\n";
   } else {
           print "Error: couldn"t rename $filename to $filename2!\n";
   }

?>

 </source>