Google Answers Logo
View Question
Q: php ( Answered,   0 Comments )
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?
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)
     $perms = fileperms($oldname);
     return copy($oldname, $newname) && chmod($newname, $perms);
   else if(is_dir($oldname)){
     my_dir_copy($oldname, $newname);
     die("Cannot copy file: $oldname (it's neither a file nor a directory)");
  function my_dir_copy($oldname, $newname) 
   $dir = opendir($oldname);
   while($file = readdir($dir)){
     if($file == "." || $file == ".."){
     my_copy("$oldname/$file", "$newname/$file");

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.

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 with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

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