Reputation: 323
Is it possible / easy to copy a file from one place (say index.php
in /mypage/homes/
) to folders in another folder (for example, in friends
there might be pfox
, sam
, uni
) using PHP?
So the file index.php
would be copied to friends/pfox
, friends/uni
and so on?
To be obvious, the file structure is as so:
update.php (The file you have to write)
mypage
|_homes
|_index.php
friends
|_pfox <--Copy index.php to here!
|_sam <--And here!
|_uni <--And here!
Upvotes: 2
Views: 134
Reputation: 8610
Might be something like this
foreach (new DirectoryIterator('./friends') as $fileInfo) {
if($fileInfo->isDir()) {
copy('./mypage/homes/index.php', $fileInfo->getPathname() . '/index.php');
}
}
You might add code to test if copy
failed.
Edit: Use getPathname
instead of getPath
.
Upvotes: 2
Reputation: 140
Something like http://php.net/manual/en/function.copy.php maybe?
The sintax is very simple
copy($file_path, $destination_path);
Upvotes: 0