简体   繁体   中英

How to insert .doc file content into mysql table

I need to insert a doc file into mysql table using php.

I have the file format like:

演示.doc .

I want all the titles (eg Resume ) be inserted into to Type column, and subtitles (eg Jobtitle ) be inserted into title field in mysql table.

I have a form

<FORM ENCTYPE="multipart/form-data" ACTION="{$_SERVER['PHP_SELF']}" METHOD=POST>
Upload this file: <INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="submit" name=submit></FORM>

So, how could I make it happen?

YOu have to save it as a binary.

Here a good tutorial:

http://mirificampress.com/permalink/saving_a_file_into_mysql

You have the following choices:

  • Store the file in the database using the BLOB column type. The file then physically resides in the database. For performance reasons, this is probably not the best idea if you are storing lots of files.

  • Store the file in a directory, then store the path to the file in your database. That means, everytime you do a retrival, you look up the path in the database first, then using that path you should be able to fetch the file using PHP.

The second method would probably offer better performance in most cases.

From my understanding of the question you want to read the content of the.doc files into a MySQL table using PHP.

.doc is a proprietary format which means reading in PHP is going to be exceptionally difficult. You'll probably want to look at the COM functions: http://www.php.net/manual/en/book.com.php

However, these are only available on the Windows version of PHP (for obvious reasons).

If you can save the Word files as RTF or TXT you may have a better chance. Newer versions of word also use the.docx format which is the document saved in an open XML format, which again will be easier to parse with PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM