docx를 생성하고 서버에서 다운로드하고 있습니다.docx 파일을 다운로드하는 중 오류가 발생했습니다.
private static function downloadFile($fileDir)
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($fileDir));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fileDir));
readfile($fileDir);
}
이것은 저장 기능입니다. 서버에서 임시 디렉토리에 파일을 열면 작동합니다. 그러나 다운로드 후 "파일이 손상되었습니다."라는 오류 메시지가 나타납니다. 나는 모든 파일을 복원하고 파일을 복원하려고합니다. 오류가 어디 있습니까?
출력 스트림에 다른 것을 표시하거나 표시하는 것일 수도 있습니다. –
파일을 16 진수 편집기에서 열고 파일의 시작과 끝 부분에 "zippish"가 아닌 것을 찾으십시오. PHP의 다른 출력 (예 : 경고)은 해당 파일의 일부가되어 손상된 것처럼 보입니다. –