압축해서 다운로드 받기

$dir_file = "$docroot/fotofiles/";		// 파일이 있는 디렉토리
$dir_tar = "$docroot/fotofiles/down/";	// 파일을 묶어서 저장할 디렉토리
$tarname = "down.tar.gz";			// 묶은 파일명
$downfilename = "홍길동사진.tar.gz";		// 다운로드받을 파일명

chdir($dir_tar);
exec("tar czf $tarname ../file1 ../file2 ../file3");
sleep(1);	//파일이 많거나 용량이 큰경우, gzip으로 압축할 경우 1초 정도 대기
chdir($dir_file);


if(eregi("(MSIE 5.5|MSIE 6.0)", $HTTP_USER_AGENT)){
	header("content-type: application/attachment");
	header("content-length: ".filesize("$dir_tar$tarname"));
	header("content-disposition: attachment; filename=\"$downfilename\"");
	header("content-transfer-encoding: binary");
} else {
	Header("Content-type: application/octet-stream");
	header("content-length: ".filesize("$dir_tar$tarname"));
	header("content-disposition: attachment; filename=\"$downfilename\"");
	header("content-description: php generated data");
}

$fp = fopen("$dir_tar$tarname", "rb");
if (!fpassthru($fp)) {
	fclose($fp);
}


// 다운로드 후 압축파일, 압축디렉토리 삭제
$fdir = @opendir($dir_tar);
if($fdir) {
	while($ent = readdir($fdir)) {
		if($ent == "." || $ent == "..") {
			continue;
		}
		@unlink($dir_tar.$ent);
	}
	@rmdir($dir_tar);
}

'PHP' 카테고리의 다른 글

php 컴파일 없이 모듈 추가하기  (0) 2013.12.06
SMTP로 메일 전송시 제목 한글 깨짐  (0) 2013.04.17
phpThumb() 이미지 변환기  (0) 2011.07.28
php iconv 사용 할 수 없을때.  (0) 2010.08.17
if($a = $b)  (0) 2010.05.10