2012-06-21 5 views
-1

PHP를 사용하여 파일을 다운로드하려고합니다. 이제 파일이 다운로드되었지만 원래 형식으로 표시되지 않습니다 (확장자 누락). 원본 파일 확장자를 사용하여 이름을 변경 한 후에 다운로드 한 파일을 사용할 수 있습니다. 다음 코드파일 다운로드가 제대로 작동하지 않습니다.

$result['ext']="rar", 
$file="file path to the uploaded folder". 

답변

2

나는 당신이 당신의 Content-disposition 헤더의 일부로서 파일 이름에 브라우저에 확장을 보내야 확신

header("Expires: 0"); 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false); 
header("Pragma: no-cache"); 
header("Content-type: application/".$result['ext']); 
header('Content-length: '.filesize($file)); 
header('Content-disposition: attachment; filename='.$result['file_name']); 
readfile($file); 
exit; 

을 사용하고 있습니다. 코드에 대한

, 당신은이 위치를 변경해야합니다 :

header('Content-disposition: attachment; filename='.$result['file_name']); 

에 :

$filename = $result['file_name'] . '.' . $result['ext']; 
header('Content-disposition: attachment; filename=' . $filename); 
+0

감사합니다 내가 당신을 평가할 수있는 방법 지금 – user1467983

+0

을하고있다. 죄송합니다. 여기에 옵션이 표시되지 않습니다. ( – user1467983

+0

환영합니다! 질문을받은 후 15 분이 경과 할 때까지 답변을 수락 할 수있는 옵션이 없습니다. 자세한 내용은 [답변 수락 방법 작품] (http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – nickb

관련 문제