Multiple upload overwrite

ok here is my code… how do i change it so that it over writes
a file ?


$path_to_file = '/var/www-uploads/';
$files = $HTTP_POST_FILES['files'];

 if (!ereg("/$", $path_to_file))
         $path_to_file = $path_to_file."/";
foreach ($files['name'] as $key=>$name) {
   if ($files['size'][$key]) {
      // clean up file name
      $name = ereg_replace("[^a-z0-9._]", "",
        str_replace(" ", "_",
            str_replace("%20", "_", strtolower($name)
            )
        )
      );
      $location = $path_to_file.$name;
           while (file_exists($location))
         $location .= ".copy"; 
      copy($files['tmp_name'][$key],$location);
      unlink($files['tmp_name'][$key]);
      echo "
<br>Successfully uploaded file: $name.";
   }
} 

and could someone explain this to me… ( if u can please) i cant seem to understand it… aim : saringk

i dont think you need to write a script to overwrite the file. in asp you don’t

this script wont over write a file if u upload with the same name…