2013-02-05 64 views
1

如何查看使用php的doc,docx文件?有任何PHP或jQuery脚本可用。我需要显示求职者通过打开的文档中恢复网上在线文档,Docx查看器在PHP?

或任何功能或类可用。请让我知道你的建议。

+2

http://stackoverflow.com/questions/7358637/reading-doc-file-in-php看到此链接 – naveen

回答

2

您可以获取从DOCX文档和文件的内容,可以在浏览器中显示它们,但你不能表现出它作为你在的Microsft字看,你需要对其进行格式化。

裁判:http://phpword.com

或者你需要写一个浏览器插件,以确定的.docx exetension,并显示在那里,为PDF文件。

<?php 
    function read_file_docx($filename){ 

     $striped_content = ''; 
     $content = ''; 

     if(!$filename || !file_exists($filename)) return false; 

     $zip = zip_open($filename); 

     if (!$zip || is_numeric($zip)) return false; 


     while ($zip_entry = zip_read($zip)) { 

      if (zip_entry_open($zip, $zip_entry) == FALSE) continue; 

      if (zip_entry_name($zip_entry) != "word/document.xml") continue; 

      $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); 

      zip_entry_close($zip_entry); 
     }// end while 

     zip_close($zip); 

     //echo $content; 
     //echo "<hr>"; 
     //file_put_contents('1.xml', $content);  

     $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content); 
     $content = str_replace('</w:r></w:p>', "\r\n", $content); 
     $striped_content = strip_tags($content); 

     return $striped_content; 
    } 



    $filename = "customers.docx"; 

    $content = read_file_docx($filename); 
    if($content !== false) { 

     echo nl2br($content); 
    } 
    else { 
     echo 'Couldn\'t find the file. Please check that file.'; 
    } 
+0

嗨prasanth,不幸的是给你的代码是不工作的两个DOC,DOCX和,你能进一步提醒我,谢谢你的回复。 –

+0

它将适用于docx,你有任何错误?请在'$ filename =“customers.docx中提供您的文件名;'将docx文件保存在与php文件相同的目录中,或者给出相关路径。这是一个工作代码:) –

+0

没有错误,我发现,但屏幕保持空白。 –