매개 변수를받은 스크립트가 클라이언트 브라우저에 파일을 다운로드합니다. 파일이 docent 루트 아래에서 액세스 할 수있는 폴더에 없습니다.PHP 파일 다운로드는 상단에 줄 바꿈이있는 두 줄을 넣습니다.
내 스크립트가 pdf의 작업을 잘 실행하지만 워드 도트는 실행하지 않습니다.
나는 쇼 기호가있는 메모장 + + 파일을 검사했으며 pdf와 docs는 메모장 ++에 따라 LF가 포함 된 맨 위에 두 줄이 있습니다 (어도비 리더는 용서하는 것처럼 보입니다).
나는 내가 생각할 수있는 모든 것을 검사했다. 나는 파일을 합치기 위해 파일을 전달하려고 시도했다. php 태그를 열기 전에 공백이 없는지 검사했다. 모든 요소를 반복하는 배열로 파일을 만들었고 "\ n"을 포함하면 forst 두 개를 반향하지 않았다.
이 아파치 설정 문제가 있습니까?
예 스크립트 : 나는 오프닝 PHP 태그 전에 PHP 태그 또는 공백을 닫는 페이지의 렌더링에 사용되는 모든 파일을 검사했다
<?php
class TrainingDatabase_IndexController extends Zend_Controller_Action
{
public function downloadAction()
{
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
// Get filepath and decode it from get param
$filepath = urldecode($this->_request->getParam('directory'));
// Return the basename for save as filename
$filename = basename($filepath);
// Set the headers
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/octet-stream');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Expires: 0');
header('Content-Length: '.filesize($filepath));
// Make sure nothing is left in the browser
ob_clean();
flush();
// Output the file
readfile($filepath);
}
}
콘텐츠 형식을 옥텟 스트림으로 설정하는 대신 Word에서는 application/msword를, PDF 파일에는 application/pdf를 사용해보십시오. 또한 $ filepath 변수는 파일 자체가 아니라 디렉토리에 대한 경로 만 포함합니까? 그렇다면 파일 크기 ($ filepath)가 무언가를 엉망으로 만들 수 있습니다. – edwardmp
포함 된 파일 중 끝에 "?>"이 있습니까? 공백으로 인해이 또한 발생할 수 있습니다. –
안녕하세요, Tim은 경로를 구성하는 모든 파일에 꼬리표가 없나요?> 태그가 없습니다. 나는 또한 파일에 공백을 보장하지 않았다. 고마워, ronnie –