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
I found this solution :
"update blob_table set blob_col='LOAD_FILE('$tmp_name')";
where $tmp_name
is the file you upload, and this is the answer for this 6 years old question, using LOAD_FILE
function. may be this is a newly added function to mysql.
Docx is a zipped file type See Tag Wiki
That's why you can't get the content of the document from the raw content.
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:
<?php
/*Name of the document file*/
$document = 'filename.docx';
/**Function to extract text*/
function extracttext($filename) {
//Check for extension
$ext = end(explode('.', $filename));
//if its docx file
if($ext == 'docx')
$dataFile = "word/document.xml";
//else it must be odt file
else
$dataFile = "content.xml";
//Create a new ZIP archive object
$zip = new ZipArchive;
// Open the archive file
if (true === $zip->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)