php 다운로드 괴상한 현상
해결과제 : 유저가 웹페이지에서 다운로드 버튼을 클릭하면
특정 폴더안에 있는 파일들을 자동으로 .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;
|
댓글을 작성하시려면 로그인이 필요합니다.
로그인
프로그램
태그 필터 (최대 3개)
전체
개발자
소스
기타
mysql
팁자료실
javascript
php
linux
flash
정규표현식
jquery
node.js
mobile
웹서버
os
프로그램
강좌
썸네일
이미지관련
도로명주소
그누보드5
기획자
견적서
계약서
기획서
마케팅
제안서
seo
통계
서식
통계자료
퍼블리셔
html
css
반응형
웹접근성
퍼블리싱
표준화
반응형웹
홈페이지기초
부트스트랩
angularjs
포럼
스크린리더
센스리더
개발자톡
개발자팁
퍼블리셔톡
퍼블리셔팁
기획자톡
기획자팁
프로그램강좌
퍼블리싱강좌
댓글 4개
둘 다 동시에 테스트해보고
다운로드된 zip 파일의 파일사이즈를 체크해보세요
http://php.net/manual/en/function.readfile.php
http://php.net/manual/en/function.readfile.php
이 페이지에 있는 샘플 소스로 적용했더니 바로 되네요.
정말 감사합니다.ㅜ 와 이걸로 한 5시간 헤맨것 같은데 해결되었네요.