I am trying to copy all the files from a directory to another directory in php.
$copy_all_files_from = "layouts/";
$copy_to = "Website3/";
Can someone help me do this please.
I am trying to copy all the files from a directory to another directory in php.
$copy_all_files_from = "layouts/";
$copy_to = "Website3/";
Can someone help me do this please.
Easiest:
`cp -r $copy_all_files_from $copy_to`
Unless you're on Windows. Without shelling, it's a bit more complex: read directory, iterate on files (if it's a directory, recurse), open each, iterate while not end of file, read block and write it.
UPDATE: doh, PHP has copy
...
Something like this(untested):
<?php
$handle = opendir($copy_all_files_from);
while (false !== ($file = readdir($handle))) {
copy( $file, $copy_to);
}
To use Amadan's method, you should be able to use this php function: shell_exec();
Not sure since I never need to use server commands