Friday, July 31, 2009

How to copy a directory to a new one using name from script in php?

i have a script in php that allows users to create a directory on my site, i tried the copy(); function doesnt work say directory all ready exist.i need it to take a directory and copy the files to the one just made. tried tons of diffent scripts so far none work.

How to copy a directory to a new one using name from script in php?
copy("fromdir/filename.txt", "todir/filename.txt");





If you want to move all files in a particular directory into another directory, you'll need to get all the files into an array and loop through them. Something like (untested!):





$copyfiles = glob("fromdir/*");


foreach ($copyfiles as $copyfile) {


copy($copyfile, "targetdir/".basename($copyfile));


}

business cards

No comments:

Post a Comment