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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序