해결과제 : 유저가 웹페이지에서 다운로드 버튼을 클릭하면
특정 폴더안에 있는 파일들을 자동으로 .zip 파일로 압축한후 다운로드 시키고
다운로드가 완료되면 .zip파일을 삭제시키는것입니다.
1. 나타난 괴상한 현상
--> 유저페이지에서는 이상없이 잘되고 있는 소스를 그대로 동일 경로에 복사해서
관리자페이지에서 실행시켰는데..
압축 잘되고, 다운로드도 되지만, 다운로드 한 파일을 로컬에서 압축 풀려고 하면
"지원되지 않는 압축 포맷입니다." 이런식으로 나옵니다.
혹시나 압축 과정에 문제가 있었나 싶어서, 생성된 zip파일을 ftp랑 web주소로 접근해서
다운로드 받았더니...그렇게 다운받은 파일은 압축이 잘 풀리더군요.
똑같은 파일인데 말이죠.
그렇다면 압축과정에는 문제가 없었을 것이라고 유추할 수가 있어서
순수 다운로드 과정의 문제라고 생각했지만...
아래의 다운로드 부분 소스에서 문제가 될 만한 사항은 전혀 없는것 같은데
참 괴상한 괴상이 삼촌이네요.
더구나 아래 소스랑 완전 100% 동일한 다운로드 소스를 같은 사이트의
다른 페이지에서도 사용하고 있는데..또 거긴 아주 정상적으로 잘 되더군요.
정말 괴상하네요.
//여기서 부턴 다운로드 하는 부분
$len = filesize($file);
$filename = basename($file);
$ctype="application/zip";
$download_rate = 500;
if(file_exists($file) && is_file($file)){
//Begin writing headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Descript-xion: File Transfer");
//Use the switch-generated Content-Type
header("Content-Type: $ctype");
//Force the download
$header="Content-Disposition: attachment; filename=".$filename.";";
header($header );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
//@readfile($file);
// flush content
flush();
// open file stream
$fp = fopen($file,"r");
while(!feof($fp)) {
// send the current file part to the browser
print fread($fp, round($download_rate * 1024));
// flush the content to the browser
flush();
// sleep one second
sleep(1);
}
fpassthru($fp);
fclose($fp);
unlink($file);
}else{
?>
<script language="javascript">
alert('error');
</script>
<?
}
exit;
특정 폴더안에 있는 파일들을 자동으로 .zip 파일로 압축한후 다운로드 시키고
다운로드가 완료되면 .zip파일을 삭제시키는것입니다.
1. 나타난 괴상한 현상
--> 유저페이지에서는 이상없이 잘되고 있는 소스를 그대로 동일 경로에 복사해서
관리자페이지에서 실행시켰는데..
압축 잘되고, 다운로드도 되지만, 다운로드 한 파일을 로컬에서 압축 풀려고 하면
"지원되지 않는 압축 포맷입니다." 이런식으로 나옵니다.
혹시나 압축 과정에 문제가 있었나 싶어서, 생성된 zip파일을 ftp랑 web주소로 접근해서
다운로드 받았더니...그렇게 다운받은 파일은 압축이 잘 풀리더군요.
똑같은 파일인데 말이죠.
그렇다면 압축과정에는 문제가 없었을 것이라고 유추할 수가 있어서
순수 다운로드 과정의 문제라고 생각했지만...
아래의 다운로드 부분 소스에서 문제가 될 만한 사항은 전혀 없는것 같은데
참 괴상한 괴상이 삼촌이네요.
더구나 아래 소스랑 완전 100% 동일한 다운로드 소스를 같은 사이트의
다른 페이지에서도 사용하고 있는데..또 거긴 아주 정상적으로 잘 되더군요.
정말 괴상하네요.
//여기서 부턴 다운로드 하는 부분
$len = filesize($file);
$filename = basename($file);
$ctype="application/zip";
$download_rate = 500;
if(file_exists($file) && is_file($file)){
//Begin writing headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Descript-xion: File Transfer");
//Use the switch-generated Content-Type
header("Content-Type: $ctype");
//Force the download
$header="Content-Disposition: attachment; filename=".$filename.";";
header($header );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
//@readfile($file);
// flush content
flush();
// open file stream
$fp = fopen($file,"r");
while(!feof($fp)) {
// send the current file part to the browser
print fread($fp, round($download_rate * 1024));
// flush the content to the browser
flush();
// sleep one second
sleep(1);
}
fpassthru($fp);
fclose($fp);
unlink($file);
}else{
?>
<script language="javascript">
alert('error');
</script>
<?
}
exit;
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기