php复制目录所有文件

<?php
$descriptorspec = array(
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$pipes = array();
$command = "cp -r /源文件目录/* /目标文件目录";
$resource = proc_open($command, $descriptorspec, $pipes);

$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
fclose($pipe);
}

$status = trim(proc_close($resource));

如果成功$status为0,$stdout是命令输出;失败则$status为错误code,$stderr为对应错误信息字符串

猜你喜欢

转载自blog.51cto.com/hjun169/2322062