mysql blob类型读取和存储,获取以blob类型保存在mysql dabase中的docx文件的内容

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 unreadable content.This this is working well for file having extention .doc but i don't know why it is not working for the .docx file.If any answer please help with proper explanation.

解决方案

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:

/*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);

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值