- HTML to docx Converter 서버에 저장하지 않고 다운로드시키기
1 사전 작업[ | ]
2 htmltodocx1.php 작성[ | ]
Console
Copy
[root@zetawiki ~]# cd /var/www/html
[root@zetawiki html]# mkdir -p ex/htmltodocx
[root@zetawiki html]# cd ex/htmltodocx
[root@zetawiki htmltodocx]# pwd
/var/www/html/ex/htmltodocx
[root@zetawiki htmltodocx]# vi htmltodocx1.php
PHP
Copy
<?php
require_once 'htmltodocx/phpword/PHPWord.php';
require_once 'htmltodocx/simplehtmldom/simple_html_dom.php';
require_once 'htmltodocx/htmltodocx_converter/h2d_htmlconverter.php';
$html = '<html>
<body>
<h1>Hello 친구들</h1>
<ul>
<li>하나</li>
<li>둘</li>
</ul>
<table>
<tr><td>1</td><td>한놈</td></tr>
<tr><td>2</td><td>두시기</td></tr>
<tr><td>3</td><td>석삼</td></tr>
</table>
</body>
</html>';
$html_dom = new simple_html_dom();
$html_dom->load($html);
$html_arr = $html_dom->find('html',0)->children();
$phpWord = new PHPWord();
$section = $phpWord->createSection();
$state = array(
'phpword_object' => &$phpWord,
);
htmltodocx_insert_html($section, $html_arr[0]->nodes, $state);
$writer = PHPWord_IOFactory::createWriter($phpWord, 'Word2007');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="htmltodocx1.docx"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
3 테스트[ | ]
- 웹브라우저에서 http://서버주소/ex/htmltodocx/htmltodocx1.php 접속
- 예제: http://zetawiki.com/ex/htmltodocx/htmltodocx1.php
- htmltodocx1.docx가 다운로드 된다...
4 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.