디렉토리 카피하기

· 2005-09-29 (목) 18:18:56 · 3180 · 2
제로보드에서 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);

?>

위에것을 호스트에 올려놓으시고 실행 시키시면 됩니다. 물론 위에 있는 디렉토리는 사용자에게
알맞게 바꾸셔야겠죠. 하위디렉토리는 처리하지 않았습니다.
|

댓글 2개

감사합니다.
감사합니다. cp 명령어 같은건가요? 해당 디렉토리를 이동하는 건가요?
댓글을 작성하시려면 로그인이 필요합니다.

그누4 팁자료실

3,309건

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요. 나누면 즐거움이 커집니다.

+
제목 글쓴이 날짜 조회
05-10-01 조회 1.1만
05-09-30 조회 1만
05-09-29 조회 4,369
05-09-29 조회 4,225
05-09-29 조회 3,181
05-09-26 조회 7,261
05-09-24 조회 1.4만
05-09-23 조회 3,358
05-09-23 조회 6,320
05-09-23 조회 5,112
05-09-23 조회 5,867
05-09-23 조회 3,292
05-09-22 조회 3,064
05-09-21 조회 3,010
05-09-19 조회 4,681
05-09-15 조회 5,471
05-09-15 조회 3,719
05-09-14 조회 7,721
05-09-14 조회 7,855
05-09-12 조회 6,344