2016-10-31 3 views
0

나는 웹 개발자입니다.다운로드 경로를 PHP로 설정하는 방법

DownloadController.php 나는 'file.zip'및 다운로드 경로 다운로드 희망

$local_file = 'file.zip'; 
$download_file = 'd:\temp\download.zip'; 
if(file_exists($local_file)) { 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename="'.basename($local_file).'"'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($local_file)); 
    readfile($download_file); 
} 

:

누구든지 나를 도울 거라고 \ 임시 \의 download.zip '을! 감사합니다.

답변

0

당신은 파일을 다운로드 코드를 사용할 수 있습니다 :

return response()->download($pathToFile); 

또는 download 방법은 download 파일에 사용자의 브라우저를 강제로 응답을 생성하기 위해 사용될 수있다

return response()->download($pathToFile, $name, $headers) 

주어진 경로에서. 다운로드 메서드는 파일 이름을 메서드의 두 번째 인수로 받아들입니다.이 메서드는 파일을 다운로드하는 사용자가 볼 수있는 파일 이름을 결정합니다.

Docs

: 마지막으로, 당신은 메서드의 세 번째 인수로 HTTP 헤더의 배열을 통과 할 수있다
관련 문제