나는 phpdocx pro를 사용하여 from 템플릿에 .docx 파일을 생성하는 프로젝트를 가지고 있습니다. 파일을 쉽게 다운로드 할 수 있지만 MS Word 2010에서 파일을 다운로드하여 열 때 프로그램에서 내용에 문제가있어 파일을 열 수 없다고보고합니다. "파일이 손상되었습니다. 열 수 없습니다 ". Word는 문서를 복구 할 수 있지만 문제는 여전히 처음부터 손상되어서는 안된다는 것을 의미합니다. 내가 파일을 얻기 위해 자신의 createDocxAndDownload()
기능을 사용하려고했다, 원래phpdocx로 손상된 .docx 다운로드
function generateUnitDesign(){
if($this->populateRecords()){
require_once dirname(__FILE__).'/phpdocx/classes/CreateDocx.inc';
$filename = 'UnitDesignTemplate-'.str_replace(' ', '', $this->rec->title);
//Create Document
$document = new CreateDocx();
$document->addTemplate(dirname(__FILE__).'/templates/unitdesigntemplate.docx');
// Fill in text fields
$document->addTemplateVariable('TITLE', $this->rec->title);
$document->addTemplateVariable('CHALLENGE', $this->rec->challenge, 'html');
$document->addTemplateVariable('HOOK', $this->rec->hook, 'html');
$document->addTemplateVariable('RESEARCH', $this->rec->research, 'html');
$document->addTemplateVariable('AUDIENCE', $this->rec->audience, 'html');
$document->addTemplateVariable('SUMMARY', $this->rec->project_brief, 'html');
$document->addTemplateVariable('RESOURCES', $this->rec->resources, 'html');
$document->addTemplateVariable('REQUIREMENTS', $this->rec->requirements, 'html');
$document->addTemplateVariable('SCAFFOLDING', $this->rec->scaffolding, 'html');
$document->createDocx($filename);
unset($document);
header("Content-Type: application/vnd.ms-word");
header("Content-Length: ".filesize($filename.'.docx'));
header('Content-Disposition: attachment; filename='.$filename.'.docx');
header('Content-Transfer-Encoding: binary');
ob_clean();
flush();
readfile($filename.'.docx');
unlink($filename.'.docx');
}
}
하지만 서버에 .DOCX 파일의 복사본을 떠날 것이다 :
이 나는 문서를 생성하고있어 어떻게 , 그것은 이상적이지 않았다. 내가 놓친 게 있니? 손을 빌려주는 phpdocx에 더 많은 경험을 가진 사람이 있습니까?
편집 : 글쎄, 나는 바보처럼 느껴진다. 파일을 출력하는 코드 부분까지 문제를 좁히고 나면, 마침내 16 진수 편집기에서 파일을 열었습니다. 문제는 파일이 성공적으로 출력 된 후 웹 프론트 엔드가 HTML의 시작 부분을 끝에 추가한다는 것입니다. docx 파일은 '손상된'파일을 만듭니다.
exit;
페카 : 새 정보와 함께이 대답하고 싶은 경우에, 나는 당신의 대답을 받아 들일 것이 한 줄 바로 unlink()
후 전체를 고정. 확인 확인 후 print print_r($this->rec->variable_name, true);
과 :
파일을 조사 했습니까? PHP 오류 메시지가 포함되어있을 것입니다. –
@Pekka 오류 없음 ... 파일에 추가 된 일부 HTML의 윗부분. –