백엔드 개발 PHP 튜토리얼 PHP는 단어를 내보내는 코드를 생성합니다(그림 포함 가능).

PHP는 단어를 내보내는 코드를 생성합니다(그림 포함 가능).

Jul 25, 2016 am 09:04 AM

  1. /**************************************************** *******************

  2. 클래스: Mht File Maker
  3. 버전: 1.2 베타
  4. 링크:bbs.it-home.org
  5. 저자 : Wudi
  6. 설명: 해당 클래스에서는 .mht 파일을 만들 수 있습니다.
  7. ************************ ***********************************************/

  8. class MhtFileMaker{

  9. var $config = array();
  10. var $headers = array();
  11. var $headers_exists = array();
  12. var $files = array();
  13. var $boundary;
  14. var $dir_base;
  15. var $page_first;

  16. function MhtFile($config = array()){

  17. < p>}

  18. function SetHeader($header){

  19. $this->headers[] = $header;
  20. $key = strtolower(substr($header, 0, strpos($header, ':')));
  21. $this->headers_exists[$key] = TRUE;
  22. }

  23. function SetFrom($ from){

  24. $this->SetHeader("From: $from");
  25. }

  26. function SetSubject($subject){

  27. $this- >SetHeader("제목: $subject");
  28. }

  29. function SetDate($date = NULL, $istimestamp = FALSE){

  30. if ($date = = NULL) {
  31. $date = time();
  32. }
  33. if ($istimestamp == TRUE) {
  34. $date = date('D, d M Y H:i:s O', $date);
  35. }
  36. $this->SetHeader("날짜: $date");
  37. }

  38. function SetBoundary($boundary = NULL) {

  39. if ($boundary == NULL) {
  40. $this->boundary = '--' . strtoupper(md5(mt_rand())) . '_MULTIPART_MIXED';
  41. } else {
  42. $this->boundary = $boundary;
  43. }
  44. }

  45. function SetBaseDir($dir){

  46. $this->dir_base = str_replace("", "/", realpath($dir));
  47. }

  48. function SetFirstPage($filename){

  49. $this->page_first = str_replace("", "/", realpath("{$this->dir_base}/$filename"));
  50. }

  51. < p>function AutoAddFiles(){
  52. if (!isset($this->page_first)) {
  53. exit ('첫 번째 페이지를 설정하지 않습니다.');
  54. }
  55. $filepath = str_replace ($this->dir_base, '', $this->page_first);
  56. $filepath = 'http://mhtfile' . $filepath;
  57. $this->AddFile($this->page_first, $filepath, NULL);
  58. $this->AddDir($this->dir_base);
  59. }< /p>
  60. function AddDir($dir){

  61. $handle_dir = opendir($dir);
  62. while ($filename = readdir($handle_dir)) {
  63. if (( $filename!='.') && ($filename!='..') && ("$dir/$filename"!=$this->page_first)) {
  64. if (is_dir("$dir/ $filename")) {
  65. $this->AddDir("$dir/$filename");
  66. } elseif (is_file("$dir/$filename")) {
  67. $filepath = str_replace ($this->dir_base, '', "$dir/$filename");
  68. $filepath = 'http://mhtfile' . $filepath;
  69. $this->AddFile("$dir/$filename", $filepath, NULL);
  70. }
  71. }
  72. }
  73. closedir($handle_dir);
  74. }

  75. function AddFile($filename, $filepath = NULL, $encoding = NULL){

  76. if ($filepath == NULL) {
  77. $filepath = $ filename;
  78. }
  79. $mimetype = $this->GetMimeType($filename);
  80. $filecont = file_get_contents($filename);
  81. $this->AddContents($filepath, $mimetype , $filecont, $encoding);
  82. }

  83. function AddContents($filepath, $mimetype, $filecont, $encoding = NULL){

  84. if ($encoding = = NULL) {
  85. $filecont = Chunk_split(base64_encode($filecont), 76);
  86. $encoding = 'base64';
  87. }
  88. $this->files[] = array(' 파일 경로' => $filepath,
  89. 'mimetype' => $mimetype,
  90. 'filecont' => $filecont,
  91. '인코딩' => ;/p>
  92. function CheckHeaders(){

  93. if (!array_key_exists('date', $this->headers_exists)) {
  94. $this->SetDate(NULL, TRUE );
  95. }
  96. if ($this->boundary == NULL) {
  97. $this->SetBoundary();
  98. }
  99. }

  100. function CheckFiles(){

  101. if (count($this->files) == 0) {
  102. FALSE를 반환;
  103. } else {
  104. TRUE를 반환;
  105. }
  106. }

  107. function GetFile(){

  108. $this->CheckHeaders();
  109. if (!$this->CheckFiles()) {
  110. exit ('파일이 추가되지 않았습니다.');
  111. }
  112. $contents = implode("rn", $this->headers);
  113. $contents .= "rn";
  114. $contents .= "MIME 버전: 1.0rn";
  115. $contents .= "콘텐츠 유형: multipart/관련;rn";
  116. $contents .= "tboundary="{$this-> 경계}";rn";
  117. $contents .= "ttype="" . $this->files[0]['mimetype'] . ""rn";
  118. $contents .= "X-MimeOLE: 제작: Mht File Maker v1.0 betarn";
  119. $contents .= "rn";
  120. $contents .= "이것은 MIME 형식의 여러 부분으로 구성된 메시지입니다.rn";
  121. $contents . = "rn";
  122. foreach ($this->files as $file) {
  123. $contents .= "--{$this->boundary}rn";
  124. $contents .= " 콘텐츠 유형: $file[mimetype]rn";
  125. $contents .= "콘텐츠 전송-인코딩: $file[encoding]rn";
  126. $contents .= "콘텐츠 위치: $file[filepath ]rn";
  127. $contents .= "rn";
  128. $contents .= $file['filecont'];
  129. $contents .= "rn";
  130. }
  131. $contents .= "--{$this->boundary}--rn";
  132. return $contents;
  133. }

  134. function MakeFile($filename){

  135. $contents = $this->GetFile();
  136. $fp = fopen($filename, 'w');
  137. fwrite($fp, $contents);
  138. fclose($fp);
  139. }

  140. function GetMimeType($filename){

  141. $pathinfo = pathinfo($filename);
  142. 스위치($pathinfo['extension']) {
  143. case 'htm': $mimetype = 'text/html'; break;
  144. case 'html': $mimetype = 'text/html'; break;
  145. case 'txt': $mimetype = 'text/plain'; break;
  146. case 'cgi': $mimetype = 'text/plain'; break;
  147. case 'php': $mimetype = 'text/plain'; break;
  148. case 'css': $mimetype = 'text/css'; break;
  149. case 'jpg': $mimetype = 'image/jpeg'; break;
  150. case 'jpeg': $mimetype = 'image/jpeg'; break;
  151. case 'jpe': $mimetype = 'image/jpeg'; break;
  152. case 'gif': $mimetype = 'image/gif'; break;
  153. case 'png': $mimetype = 'image/png'; break;
  154. 기본값: $mimetype = 'application/octet-stream'; break;
  155. }
  156. return $mimetype;
  157. }
  158. }
  159. ?>

复system代码

2、导출단어文件exportdoc.php

  1. /**

  2. * HTML 코드를 기반으로 단어 문서 콘텐츠 가져오기
  3. * 본질적으로 mht인 문서를 생성합니다. 이 기능은 파일 콘텐츠를 분석하고 원격 위치에서 페이지의 이미지 리소스를 다운로드합니다.
  4. * 이 기능은 함수는 MhtFileMaker 클래스에 따라 다릅니다.
  5. * 이 함수는 img 태그를 분석하고 src의 속성 값을 추출합니다. 단, src의 속성 값은 따옴표로 묶어야 합니다. 그렇지 않으면 추출할 수 없습니다.
  6. *
  7. * @param string $content HTML content
  8. * @param string $absolutePath 웹 페이지의 절대 경로입니다. . HTML 콘텐츠의 이미지 경로가 상대 경로인 경우 함수가 자동으로 절대 경로를 채울 수 있도록 이 매개변수를 입력해야 합니다. 이 매개변수는 /
  9. * @param bool $isEraseLink로 끝나야 합니다. HTML 콘텐츠에서 링크를 제거할지 여부
  10. */
  11. include_once("docclass.php" );
  12. 함수 getWordDocument( $content , $absolutePath = "" , $isEraseLink = true )
  13. {
  14. $mht = new MhtFileMaker();
  15. if ($isEraseLink)
  16. $content = preg_replace ('/(s*.*?s*)/i' , '$1' , $content); //去掉链接

  17. $images = array();

  18. $files = array();
  19. $matches = array();
  20. //这个算法要求src后的属性值必须使用引号括起来
  21. if ( preg_match_all('//i',$content ,$matches ) )
  22. {
  23. $arrPath = $matches[1];
  24. for ( $i=0;$i{
  25. $path = $arrPath[$i];
  26. $imgPath = Trim( $path );
  27. if ( $imgPath != "" )
  28. {
  29. $files[] = $imgPath;
  30. if( substr($imgPath,0,7) == 'http://')
  31. {
  32. //绝对链接 不加前缀
  33. }
  34. 그 외
  35. {
  36. $imgPath = $absolutePath.$imgPath;
  37. }
  38. $images[] = $imgPath;
  39. }
  40. }
  41. }
  42. $mht->AddContents("tmp.html",$mht->GetMimeType("tmp.html"),$content);

  43. for( $ i=0;$i{

  44. $image = $images[$i];
  45. if ( @fopen($image , 'r') )
  46. {
  47. $imgcontent = @file_get_contents( $image );
  48. if ( $content )
  49. $mht->AddContents($files[$i],$mht->GetMimeType($image ),$imgcontent);
  50. }
  51. else
  52. {
  53. echo "file:".$image."이 존재하지 않습니다!
    ";
  54. }
  55. }

  56. return $mht->GetFile();

  57. }
  58. $content=implode("",file("http://bbs.it-home. org/print.php?id=3548"));
  59. $fileContent = getWordDocument($content,".");
  60. $fp = fopen("hugesky_word.doc", 'w');
  61. fwrite($fp, $fileContent);
  62. fclose($fp);
  63. ?>

复代码


본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) 11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) Mar 03, 2025 am 10:49 AM

종종 키워드와 추적 매개 변수로 혼란스러워하는 긴 URL은 방문자를 방해 할 수 있습니다. URL 단축 스크립트는 솔루션을 제공하여 소셜 미디어 및 기타 플랫폼에 이상적인 간결한 링크를 만듭니다. 이 스크립트는 개별 웹 사이트 a에 유용합니다

Instagram API 소개 Instagram API 소개 Mar 02, 2025 am 09:32 AM

Instagram은 2012 년 Facebook에서 유명한 인수에 이어 타사 사용을 위해 두 개의 API 세트를 채택했습니다. Instagram Graph API 및 Instagram Basic Display API입니다. 개발자는

Laravel의 플래시 세션 데이터로 작업합니다 Laravel의 플래시 세션 데이터로 작업합니다 Mar 12, 2025 pm 05:08 PM

Laravel은 직관적 인 플래시 방법을 사용하여 임시 세션 데이터 처리를 단순화합니다. 응용 프로그램에 간단한 메시지, 경고 또는 알림을 표시하는 데 적합합니다. 데이터는 기본적으로 후속 요청에만 지속됩니다. $ 요청-

Laravel Back End : Part 2, React가있는 React 앱 구축 Laravel Back End : Part 2, React가있는 React 앱 구축 Mar 04, 2025 am 09:33 AM

이것은 Laravel 백엔드가있는 React Application을 구축하는 데있어 시리즈의 두 번째이자 마지막 부분입니다. 이 시리즈의 첫 번째 부분에서는 기본 제품 목록 응용 프로그램을 위해 Laravel을 사용하여 편안한 API를 만들었습니다. 이 튜토리얼에서는 Dev가 될 것입니다

Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Mar 12, 2025 pm 05:09 PM

Laravel은 간결한 HTTP 응답 시뮬레이션 구문을 제공하여 HTTP 상호 작용 테스트를 단순화합니다. 이 접근법은 테스트 시뮬레이션을보다 직관적으로 만들면서 코드 중복성을 크게 줄입니다. 기본 구현은 다양한 응답 유형 단축키를 제공합니다. Illuminate \ support \ Facades \ http를 사용하십시오. http :: 가짜 ([ 'google.com'=> ​​'Hello World', 'github.com'=> ​​[ 'foo'=> 'bar'], 'forge.laravel.com'=>

PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 Mar 14, 2025 am 11:42 AM

PHP 클라이언트 URL (CURL) 확장자는 개발자를위한 강력한 도구이며 원격 서버 및 REST API와의 원활한 상호 작용을 가능하게합니다. PHP CURL은 존경받는 다중 프로모토콜 파일 전송 라이브러리 인 Libcurl을 활용하여 효율적인 execu를 용이하게합니다.

Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Mar 13, 2025 pm 12:08 PM

고객의 가장 긴급한 문제에 실시간 인스턴트 솔루션을 제공하고 싶습니까? 라이브 채팅을 통해 고객과 실시간 대화를 나누고 문제를 즉시 해결할 수 있습니다. 그것은 당신이 당신의 관습에 더 빠른 서비스를 제공 할 수 있도록합니다.

2025 PHP 상황 조사 발표 2025 PHP 상황 조사 발표 Mar 03, 2025 pm 04:20 PM

2025 PHP Landscape Survey는 현재 PHP 개발 동향을 조사합니다. 개발자와 비즈니스에 대한 통찰력을 제공하는 프레임 워크 사용, 배포 방법 및 과제를 탐색합니다. 이 조사는 현대 PHP Versio의 성장을 예상합니다

See all articles