디렉토리 카피하기 정보
디렉토리 카피하기본문
제로보드에서 G4로 갤러리 사진들을 카피하기 위해서 썼습니다만,
다른 용도로도 쓰일수 있습니다.
<?PHP
$fromDir = './vision/zboard/'; //소스디렉토리
$toDir = './gnuboard/'; //목적지
$chmod=0777; //8진수, 모두 허가
echo getcwd(); //현 디렉토리를 보여줍니다
echo '<br>';
//디렉토리 관련 에러처리
if (!is_writable($toDir))
echo 'target '.$toDir.' is not writable <br>';
if (!is_dir($toDir))
echo 'target '.$toDir.' is not a directory<br>';
if (!is_dir($fromDir))
echo 'source '.$fromDir.' is not a directory<br>';
$skipThese=array('.','..');
$handle=opendir($fromDir);
while (false!=($curFile=readdir($handle)))
if (!in_array($item,$skipThese))
{
// 디렉토리 끝에 /를 붙인경우 //가되므로 /로 바꿔줍니다.
$from=str_replace('//','/',$fromDir.'/'.$curFile);
$to=str_replace('//','/',$toDir.'/'.$curFile);
if (is_file($from))
{
if (@copy($from,$to))
{
@chmod($to,$chmod);
@touch($to,filemtime($from)); //카피된 화일의 날짜를 원래대로 해줍니다.
echo 'File copied from '.$from.' to '.$to.'<br>';
}
else
echo 'cannot copy file from '.$from.' to '.$to.'<br>';
}
}
closedir($handle);
?>
위에것을 호스트에 올려놓으시고 실행 시키시면 됩니다. 물론 위에 있는 디렉토리는 사용자에게
알맞게 바꾸셔야겠죠. 하위디렉토리는 처리하지 않았습니다.
다른 용도로도 쓰일수 있습니다.
<?PHP
$fromDir = './vision/zboard/'; //소스디렉토리
$toDir = './gnuboard/'; //목적지
$chmod=0777; //8진수, 모두 허가
echo getcwd(); //현 디렉토리를 보여줍니다
echo '<br>';
//디렉토리 관련 에러처리
if (!is_writable($toDir))
echo 'target '.$toDir.' is not writable <br>';
if (!is_dir($toDir))
echo 'target '.$toDir.' is not a directory<br>';
if (!is_dir($fromDir))
echo 'source '.$fromDir.' is not a directory<br>';
$skipThese=array('.','..');
$handle=opendir($fromDir);
while (false!=($curFile=readdir($handle)))
if (!in_array($item,$skipThese))
{
// 디렉토리 끝에 /를 붙인경우 //가되므로 /로 바꿔줍니다.
$from=str_replace('//','/',$fromDir.'/'.$curFile);
$to=str_replace('//','/',$toDir.'/'.$curFile);
if (is_file($from))
{
if (@copy($from,$to))
{
@chmod($to,$chmod);
@touch($to,filemtime($from)); //카피된 화일의 날짜를 원래대로 해줍니다.
echo 'File copied from '.$from.' to '.$to.'<br>';
}
else
echo 'cannot copy file from '.$from.' to '.$to.'<br>';
}
}
closedir($handle);
?>
위에것을 호스트에 올려놓으시고 실행 시키시면 됩니다. 물론 위에 있는 디렉토리는 사용자에게
알맞게 바꾸셔야겠죠. 하위디렉토리는 처리하지 않았습니다.
추천
0
0
댓글 2개
감사합니다.

감사합니다. cp 명령어 같은건가요? 해당 디렉토리를 이동하는 건가요?