I was working in job portal project, in job portal website, we give options to jobseekers upload their resume in .doc, .rtf, .txt and .pdf formats.
We’re getting lots of request from our users for uploading resumes in .docx file format. after we decided to allow upload their resumes in .docx file format. At that time I don’t know how to read the docx file using php. Finally I read docx file using php. Here i place the read docx file using php code. Use this code and read docx file using php.
<?php
function read_file_docx($filename){
$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;
}?>
Usage #1:
<?php
$filename = "file.docx";// or /var/www/html/file.docx
$content = read_file_docx($filename);
if($content !== false) {
echo nl2br($content);
}
else {
echo 'Couldn\'t the file. Please check that file.';
}
?>
Click “download” link and get the sample code.
Download
Popularity: 18% [?]
Related posts:
hey,
i tried to user your code, with the its not working
zip_open function is returning me 11. so can u please help me out what else it needed to make your code work.
thank you a lot!
I want a php script to read .doc, .docx, .txt and .pdf file.
Please help me..urgent