Laman

Showing Image from DOCX using PHP

Required:
- PHP 5.2+
- php_zip.dll for Windows or --enable-zip parameter for Linux

Basically we need a ZIP library for PHP. The reason behind this requirement is that Word document files are actually archived files with there extension changed from .zip to .docx.

Create a new PHP file and name it as extract.php and add the following code in it.

open($filename)) {   for ($i=0; $i<$zip->numFiles;$i++) {

/*Loop via all the files to check for image files*/

$zip_element = $zip->statIndex($i);

   /*Check for images*/

   if(preg_match("([^\s]+(\.(?i)(jpg|jpeg|png|gif|bmp))$)",$zip_element['name'])) { 

    /*Display images if present by using display.php*/ 

    echo "
"; } } } } readZippedImages($document); ?>

Now create another PHP file and name it as display.php and add the following code to it.
open($_GET['filename'])) {

/*Get the content of the specified index of ZIP archive*/

   echo $zip->getFromIndex($_GET['index']); 

}

$zip->close();
?>
Source: www.botskool.com

No comments:

Post a Comment

Silahkan