php 다운로드 괴상한 현상 정보
개발자 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;
추천
0
0
댓글 4개

동일한 파일을 잘되는 서버에 올려두고
둘 다 동시에 테스트해보고
다운로드된 zip 파일의 파일사이즈를 체크해보세요
둘 다 동시에 테스트해보고
다운로드된 zip 파일의 파일사이즈를 체크해보세요

readfile 을 써보세요.
http://php.net/manual/en/function.readfile.php
http://php.net/manual/en/function.readfile.php
fpassthru($fp); 를 삭제하고 해보시기 바랍니다. 소스상 두번 보내는 결과가 됩니다. zip파일의 크기를 점검해보면 정확히 알 수 있을 거 같습니다.
답변 해주신 분들 감사합니다.
http://php.net/manual/en/function.readfile.php
이 페이지에 있는 샘플 소스로 적용했더니 바로 되네요.
정말 감사합니다.ㅜ 와 이걸로 한 5시간 헤맨것 같은데 해결되었네요.
http://php.net/manual/en/function.readfile.php
이 페이지에 있는 샘플 소스로 적용했더니 바로 되네요.
정말 감사합니다.ㅜ 와 이걸로 한 5시간 헤맨것 같은데 해결되었네요.