PHP 다운로드 오류...
본문
http://i1.search.daumcdn.net/s/knowledge4_re/btn_original.png); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">원본보기
이렇게 파일을 다운로드 하려고 시도하면
download.php 가 다운로드됩니다.
아래는 소스코드 입니다. 보시죠.
<?php
$filename = 'upload/'."$_GET['file']";
$filename = str_replace( " ","+", $filename ); // 공백문자의 제거(권장)
$extension = $_GET['type'];
switch($extension) {
case "exe": $type="application/octet-stream"; break;
case "zip": $type="application/zip"; break;
case "gif": $type="image/gif"; break;
case "png": $type="image/png"; break;
case "jpeg":
case "jpg": $type="image/jpg"; break;
case "mp3": $type="audio/mpeg"; break;
case "wav": $type="audio/x-wav"; break;
case "avi": $type="video/x-msvideo"; break;
default: $type="application/force-download";
}
$filepath = $filename;
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: ".$type);
header("Content-Disposition: attachment; filename=". basename($filepath) .";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filepath));
@readfile($filepath);
?>
실제로 다운로드는 잘 되구요.
파일 이름이 저렇게 됩니다.
저 파일을 .mp3 으로 변환하면 잘 플레이 됩니다.;;
답변 1
header("Content-Disposition: attachment; filename=". basename($filepath) .";");
이게 문제인거같아요.
filename은 다운로드될 파일의 이름을 지정해주는건데 여기에 경로까지 다 들어가서 생기는 문제 같아요.