duan5991518 2018-05-08 11:10
浏览 104

在php中阅读Doc,Docx文件

I have a folder having name is upload_resume which possess .doc as well as .docx file inside it. Now I want to read any file may be it .doc or .docx .Now, what happen when I run my page it show me nothing its totally blank and show me message page not found. So, How can I fix it?

Code so far:

<?php
    $upload_resume = $row['upload_resume'];
    $path_file = "upload_resume/".basename($upload_resume);

    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);
        }
        zip_close($zip);
        $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
        $content = str_replace('</w:r></w:p>', "
", $content);
        $striped_content = strip_tags($content);
        return $striped_content;
    }
    $filename = $path_file;
    echo $filename;
        $content = read_file_docx($filename);
        if($content !== false) {

            echo nl2br($content);
        }
        else {
            echo 'Couldn\'t the file. Please check that file.';
        }   
    }
?>
  • 写回答

1条回答 默认 最新

  • duanlv2788 2018-05-08 11:21
    关注

    delete } on top ?>

    I hope this can help you

    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用