如何在php codeigniter中读取doc / docx / pdf文件中的文本/内容?

问题描述 投票:0回答:1

我正在尝试读取我们已上传的.doc或.docx文件的内容。

我正在使用带有codeigniter的php,并且我需要从文件中获取文本并将其保存在数据库中,以便我们可以轻松地进行搜索。我尝试了所有可能的方法,但到目前为止没有运气。

php codeigniter
1个回答
0
投票

一旦获得上载的文件详细信息,就可以使用以下内容解析文件的内容:

读取PHP中的doc / docx文件:https://stackoverflow.com/a/19503654/3151134

PDF解析器库:https://github.com/smalot/pdfparser

这是有关如何在CI中上传文件的基本示例,非常简单:

<< [查看文件在application / views / upload_form.php

<html> [...] <body> <?php echo $error;?> <?php echo form_open_multipart('upload/do_upload');?> <input type="file" name="userfile" /> <input type="submit" value="upload" /> </form> </body> </html>
<< [Controller
在application / controllers / Upload.php

<?php class Upload extends CI_Controller { public function __construct() { parent::__construct(); $this->load->helper(array('form', 'url')); } public function index() { $this->load->view('upload_form', array('error' => ' ' )); } public function do_upload() { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'doc|docx|pdf'; $config['max_size'] = 10000; //kilobytes // Load the Upload Library $this->load->library('upload', $config); if ( ! $this->upload->do_upload('userfile')) { $error = array('error' => $this->upload->display_errors()); $this->load->view('upload_form', $error); } else { // Get the full path of the file $fileFullPath = $this->upload->data('full_path'); /*** Parse the file and store its content in the db ***/ // After that maybe show a success page $this->load->view('<nameofsuccesspageview>'); } } } ?>

© www.soinside.com 2019 - 2024. All rights reserved.