开发者

How to copy all contents in a folder to a dir in php

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 th开发者_运维问答is please.


Something like this(untested):

<?php
$handle = opendir($copy_all_files_from);
while (false !== ($file = readdir($handle))) {
    copy( $file, $copy_to);
    }

edit:

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


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜