사용자가 링크를 클릭하면 파일을 강제로 다운로드하려고합니다. 링크를 클릭하면 압축 파일이 즉시 만들어져 사용자 컴퓨터에 다운로드됩니다. 내 코드는 localhost에서 실행될 때 작동하지만 서버에서 실행할 때 빈 페이지를 표시합니다. 파일을 다운로드하려고 할 때 빈 페이지가 나타납니다.
이
파일을 다운로드 링크입니다 :<a href="downloadfile.php"> Download </a>
그리고 이것은 downloadfile.php입니다 : 프로덕션 서버에서 사용 ziparchive 경우
<?php
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
$zip->addFromString('test.txt', "this is a test file");
$zip->close();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="testfile.zip" ');
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: '.filesize($file));
ob_clean();
flush();
readfile($file);
unlink($file);
exit();
?>
서버 응답의 상태 코드는 무엇의 상단에이 줄을 추가하려고하기 때문에 다른 문제가 있다고 생각? –
코드가 서버에서 실행되고 인스턴스 리디렉션 문제가 없는지 확인 했습니까? – Bowdzone
제작중인 경우 php.ini가 해당 지역과 다른 것으로 생각됩니다. 오류가 던졌습니다 (빈 페이지) 같아요. 아파치 로그를 살펴 봐야합니다. – Debflav