PHP를 사용하여 폴더에서 파일을 다운로드하기위한 스크립트가 있습니다. 로컬에서 작동하지만 다운로드 중 페이지에서 온라인으로 읽고 인쇄하고 있습니다. 도움을PHP가 다운로드하는 대신 파일을 읽는 중입니다.
if($result && count($result) > 0){
$row = $result[0];
$book = true;
$Location = './files/';
$bookLocation = $Location . $row['file_name']; // exampe: report.zip
if(file_exists($bookLocation)){
$fileLocation = $bookLocation;
$file_size = filesize($fileLocation);
echo 'Please wait downloading the file....';
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename=' . $row['file_name']);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $file_size);
ob_clean();
flush();
readfile($fileLocation);
exit;
}else{
echo '<h3>Sorry!, file not found...</h3>';
}
}
htaccess로 스크립트
RewriteEngine on
RewriteRule ^$ index.html
RewriteRule ^index.html$ index.php
RewriteRule ^([0-9]{1,9})(/)([^/\.]+[^/\.]+)(_+[^/\.]+)(\.html|)/?$ index.php?id=$1&cat=$3
RewriteRule ^([^/\.]+[^/\.]+)(\.html|)/?$ index.php?page=$1
RewriteRule ^(.*)(/)([0-9]{1,9})(/)(.*)(\.html|)/?$ index.php?view_file=$3&file=$5
RewriteRule ^(.*)(/)([0-9]{1,9})(/)(.*)(\.htm)/?$ index.php?download=$3
RewriteRule ^(author)(/)(.*)(.html)/?$ index.php?user=$1
감사합니다.
당신이 브라우저를 실행하지 않는로 라인
를 교체하려고? – zod
링크가있는 새 파일을 만들려고합니다. 링크가이 파일에 있습니다 .. .. 다음 새 페이지를 실행하고 링크를 클릭하십시오 !! – zod
서버가 결국 헤더를 수정합니까? – evotopid