1. 程式人生 > >php複製目錄所有檔案

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為對應錯誤資訊字串