Google Answers Logo
View Question
 
Q: php ( Answered,   0 Comments )
Question  
Subject: php
Category: Computers
Asked by: proxomos-ga
List Price: $5.00
Posted: 20 Jan 2004 03:30 PST
Expires: 19 Feb 2004 03:30 PST
Question ID: 298317
how can i copy more than one file in php?
Answer  
Subject: Re: php
Answered By: joseleon-ga on 20 Jan 2004 04:59 PST
 
Hello, proxomos:

There are several ways to do that, here is one version:

function my_copy($oldname, $newname)
  {
   if(is_file($oldname)){
     $perms = fileperms($oldname);
     return copy($oldname, $newname) && chmod($newname, $perms);
   }
   else if(is_dir($oldname)){
     my_dir_copy($oldname, $newname);
   }
   else{
     die("Cannot copy file: $oldname (it's neither a file nor a directory)");
   } 
  }
     
  function my_dir_copy($oldname, $newname) 
  {
   if(!is_dir($newname)){
     mkdir($newname);
   }
   $dir = opendir($oldname);
   while($file = readdir($dir)){
     if($file == "." || $file == ".."){
       continue;
     }
     my_copy("$oldname/$file", "$newname/$file");
   }
   closedir($dir);
  } 

You can use my_copy, which copies recursively the contents of one dir
into a target dir.

As I say, there are several ways to do it, so feel free to request for
any clarification.

Regards.
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy