Get content of docx file which saved in mysql dabase as blob type in php

后端 未结 3 1003
南旧
南旧 2021-01-22 15:25

I am saving docx file as BLOB type in mysql dadabase. after the saveing i am trying to see the content of the file through fetching the content of filed but it is showing some u

3条回答
  •  鱼传尺愫
    2021-01-22 15:52

    Make a query to select the data, then put the result in a variable. Use file_put_content to get the docx file. Just be carefull with header.

    To read it, the process is different from a doc. You have to "unzip" the docx and read the xml file inside it. You can use this function:

    open($filename)) {
            // If successful, search for the data file in the archive
            if (($index = $zip->locateName($dataFile)) !== false) {
                // Index found! Now read it to a string
                $text = $zip->getFromIndex($index);
                // Load XML from a string
                // Ignore errors and warnings
                $xml = DOMDocument::loadXML($text, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
                // Remove XML formatting tags and return the text
                return strip_tags($xml->saveXML());
            }
            //Close the archive file
            $zip->close();
        }
    
        // In case of failure return a message
        return "File not found";
    }
    
    echo extracttext($document);
    ?>
    

    (source of the code: http://www.botskool.com/geeks/how-extract-text-docx-or-odt-files-using-php)

提交回复
热议问题