Php 无法读取codeigniter中的docx文件
我想把上传简历的代码创建为doc或docx文件,并在codeigniter中获取上传简历的内容。因此,我在这里编写了如下代码:Php 无法读取codeigniter中的docx文件,php,codeigniter,Php,Codeigniter,我想把上传简历的代码创建为doc或docx文件,并在codeigniter中获取上传简历的内容。因此,我在这里编写了如下代码: function read_file_docx($filename) { //echo $filename;exit; $striped_content = ''; $content = ''; if(!$filename || !file_exists($filename)) return false; $zip = zip
function read_file_docx($filename)
{
//echo $filename;exit;
$striped_content = '';
$content = '';
if(!$filename || !file_exists($filename)) return false;
$zip = zip_open($filename);
if (!$zip || is_numeric($zip)) return false;
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry) == FALSE) continue;
if (zip_entry_name($zip_entry) != "word/document.xml") continue;
$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}// end while
zip_close($zip);
echo $content;
//echo "<hr>";
//file_put_contents('1.xml', $content);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$striped_content = strip_tags($content);
return $striped_content;
}
function f_read()
{
$filename = '/var/www/html/job_portal/uploads/resume/Nisarg.docx';
//echo $filename;
$content = $this->read_file_docx($filename);
if($content !== false) {
echo nl2br($content);
}
else {
echo 'Couldn\'t the file. Please check that file.';
}
}
function read\u file\u docx($filename)
{
//echo$filename;退出;
$striped_content='';
$content='';
如果(!$filename | |!file_存在($filename))返回false;
$zip=zip\u open($filename);
如果(!$zip |是数值($zip))返回false;
而($zip\u entry=zip\u read($zip)){
如果(zip_entry_open($zip,$zip_entry)==FALSE)继续;
如果(zip\u entry\u name($zip\u entry)!=“word/document.xml”)继续;
$content.=zip_entry_read($zip_entry,zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}//结束时
zip_close($zip);
echo$内容;
//回声“
”;
//文件内容('1.xml',$content);
$content=str_replace(“”,$content);
$content=str_replace(“”,\r\n“,$content);
$striped_content=strip_标签($content);
返回$striped_内容;
}
函数f_read()
{
$filename='/var/www/html/job_portal/uploads/resume/Nisarg.docx';
//echo$filename;
$content=$this->read\u file\u docx($filename);
如果($content!==false){
echo nl2br($content);
}
否则{
echo“无法读取该文件。请检查该文件。”;
}
}
当我调用这个f_read()时,它返回为空
这里有加载文件文件助手。那么我该如何解决它呢?看看@Danyalsandelo我已经检查过了,但无法解决我的问题。只需使用给定的代码,单据编码与单据编码不同docx@DanyalSandeelo我已经创建了simgple文档文件,并将内容写为nisarg bhavsar,然后在我打印$zip时将其返回编号19,在我上传简历时,将其显示为空白页。