2014-02-21 5 views
0

내 머리글에 어떤 문제가 있는지 말해 줄 수 있습니까? 내 다운로드가 효과적이지 않습니다. 나는 PHPWord 라이브러리를 사용하지만 난 그게단어 파일을 다운로드 할 수 없습니다.

<?php 

    require_once 'PHPWord.php'; 
    $PHPWord = new PHPWord(); 

    $section = $PHPWord->createSection(); 
    $wordText = utf8_encode($_REQUEST['TEXT']); 

    $section->addText($wordText); 

    $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); 
    //$objWriter->save('helloWorld.docx'); 
    $path = 'tmp/kikou2.docx'; 
    $objWriter->save($path); 
    //download code 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename=' .$path); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Content-Length: ' . filesize($objWriter)); 
    readfile($objWriter); 
    unlink($objWriter); // deletes the temporary file 
    exit; 


?> 

감사

답변

1

이 파일 .DOCX OfficeOpenXML에 대한 헤더 추천을

// Redirect output to a client’s web browser (.docx) 
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); 
header('Content-Disposition: attachment;filename="kikou2.docx"'); 
header('Cache-Control: max-age=0'); 
// If you're serving to IE 9, then the following may be needed 
header('Cache-Control: max-age=1'); 

// If you're serving to IE over SSL, then the following may be needed 
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past 
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified 
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 
header ('Pragma: public'); // HTTP/1.0 

Content-Type 제목에 대한주의 사항

+0

그것은 작동하지 않습니다 (그리고 다른 답변도 너무 ..), 당신은 어떤 생각을 가지고 있습니까? – So4ne

+0

내 잘못 파일을 호출하도록 허용 할 수없는 POST 아약스 요청을 사용합니다. 하지만 당신의 대답은 좋았고 도움이되었습니다, 감사합니다! – So4ne

1

추가 두 헤더 문제라고 생각하지 않습니다

header("Content-Type: application/force-download"); 
header("Content-Type: application/download"); 
+0

여러 콘텐츠 유형 표제를 사용하는 것은 의미가 없습니다. 마지막으로 사용한 내용 만 실제로 적용됩니다.이 내용을 시도한 다음 브라우저에서받은 제목을 확인하여 의미를 확인하십시오. –

1
header('Content-Description: File Transfer'); 
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); 
header('Content-Disposition: attachment; filename="'.basename($objWriter).'"'); //<<< Note the " " surrounding the file name 
header('Content-Transfer-Encoding: binary'); 
header('Connection: Keep-Alive'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 
header('Content-Length: ' . filesize($objWriter)); 
+0

여러 콘텐츠 형식 제목을 사용하는 것은 의미가 없습니다. 마지막으로 사용 된 것만 실제로 적용될 것입니다. - 이걸 시도한 다음 브라우저가받은 제목을 확인하여 제가 의미하는 바를 확인하십시오 .... 그러나 OP의 코드로 내용 처분 파일 이름 문제를 해결하기위한 명성이 –

+0

입니다. @mark : 감사합니다. 답변 됨 Edited! –

0
  $document->save($url.'temp/Form Letters1.docx'); 
      $path = $url.'temp/Form Letters1.docx'; 
      header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); 
      header('Content-Disposition: attachment;filename="Form Letters1.docx"'); 
      header('Expires: 0'); 
      header('Cache-Control: must-revalidate'); 
      header('Pragma: public'); 
      header('Content-Length: ' . filesize($path)); 
      ob_clean(); 
      flush(); 
      readfile($path); 
관련 문제