<?php
function readDocx($filePath) {
// Create new ZIP archive
$zip = new ZipArchive;
$dataFile = 'word/document.xml';
// Open received archive file
if (true === $zip->open($filePath)) {
// If done, search for the data file in the archive
if (($index = $zip->locateName($dataFile)) !== false) {
// If found, read it to the string
$data = $zip->getFromIndex($index);
// Close archive file
$zip->close();
// Load XML from a string
// Skip errors and warnings
$xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
// Return data without XML formatting tags
$contents = explode('\n',strip_tags($xml->saveXML()));
$text = '';
foreach($contents as $i=>$content) {
$text .= $contents[$i];
}
return $text;
}
$zip->close();
}
// In case of failure return empty string
return "failed";
}
?>
13 Replies - 1341 Views - Last Post: 01 August 2012 - 06:23 PM
#1
PHPDocx not displaying images when a docx file with image is converted
Posted 24 July 2012 - 08:33 PM
Well Im just wondering if any of you used php docx (http://www.phpdocx.com/download) to convert docx to html. Well it worked but the images aren't displaying. I also use this code to generate html from docx but it just get the text not the images. even the formatting aren't there. Well my requirement is to grab the docx and convert it to html. I must also get the images with that. Is there any class for it??
Replies To: PHPDocx not displaying images when a docx file with image is converted
#2
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 25 July 2012 - 07:08 AM
I'm confused. The point of DOCX is to generate Word files from your data, but you seem to want to generate an HTML file. Why convert to Word? Why not generate the HTML directly from the data?
#3
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 25 July 2012 - 07:41 AM
Isn't he trying to do the opposite? Take a word file and convert that into HTML?
#4
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 25 July 2012 - 08:25 AM
Maybe, but DOCX claims to be good at generating Word files:
It seemed to me that the starting point is data. I think that something like this is happening:
Database -> DOCX -> Wordfile -> DOCX -> HTML
If that's the case, it would be easier to go straight to HTML.
Quote
PHPDocx is a PHP library designed to generate completely dynamic and fully customizable Word documents
It seemed to me that the starting point is data. I think that something like this is happening:
Database -> DOCX -> Wordfile -> DOCX -> HTML
If that's the case, it would be easier to go straight to HTML.
#5
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 25 July 2012 - 05:24 PM
what I wanted to do is if the user uploads a docx file, it will be saved in a directory. After that, the file is accessible which the user can edit it in the web browser using tinyMCE, thats why I need to turn it into HTML. Font colors, font size weight are good but the images are dont show up. After editting, the user will press the save button and turn the HTML string into docx again. I use PHPWord for that process (html->docx) because this feature in PHPDocx is for pro users only..
#6
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 25 July 2012 - 06:50 PM
Test%205/files/files_CopyDocx/media/word/
it seems that when PHP docx tries to convert docx to html. The images are copied to this directory. I think PHP docx failed to copy it there. I tried viewing the source in the browser and find that image. This is where the image comes from. It just point to a directory but doesn’t point into a file
it seems that when PHP docx tries to convert docx to html. The images are copied to this directory. I think PHP docx failed to copy it there. I tried viewing the source in the browser and find that image. This is where the image comes from. It just point to a directory but doesn’t point into a file
#7
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 26 July 2012 - 01:11 AM
Does that directory exist? Do you have permissions to write to it?
#8
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 26 July 2012 - 07:05 PM
#9
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 27 July 2012 - 01:08 AM
The user running the script may not have permissions to create a directory there. Make sure they have write permissions on the parent directory.
#10
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 27 July 2012 - 02:55 AM
Duckington, on 27 July 2012 - 01:08 AM, said:
The user running the script may not have permissions to create a directory there. Make sure they have write permissions on the parent directory.
I already tried using mkdir("New Folder"); to create new folder. And its working. I think its the same process. But Im not still sure. I didn't put any .htaccess file inside the targetted directory. If there is more configuration about creating directory permissions, then what is it? and I will check it.
Did you use phpDocx? Have you tried the example inside that folder and trying to use the docxtohtml script?.. I really appreciate if you try.
#11
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 27 July 2012 - 03:51 AM
I've never used it tbh, so i'm just trying to make some vaguely educated guesses as to what the problem is.
Haev you checked your error log to see if anything is there?
(I'd also recommend creating your own error function to write errors to your own specific file, as that is more customisable and can make things easier to debug).
Haev you checked your error log to see if anything is there?
(I'd also recommend creating your own error function to write errors to your own specific file, as that is more customisable and can make things easier to debug).
#12
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 01 August 2012 - 05:31 PM
[Thu Aug 02 08:31:02 2012] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_, referer: http://localhost/Tes.../createHTML.php
Ive got this error from apache...
Ive got this error from apache...
#13
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 01 August 2012 - 05:57 PM
Well, do all the directories listed in this path
actually exist?
C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_
actually exist?
#14
Re: PHPDocx not displaying images when a docx file with image is converted
Posted 01 August 2012 - 06:23 PM
JackOfAllTrades, on 01 August 2012 - 05:57 PM, said:
Well, do all the directories listed in this path
actually exist?
C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_
actually exist?
Ive tried making directory here's what I get. THe directory I make is depending on the last directory before the referrer:
[Thu Aug 02 08:29:19 2012] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_, referer: http://localhost/Tes.../createHTML.php
[Thu Aug 02 08:30:05 2012] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_, referer: http://localhost/Tes.../createHTML.php
[Thu Aug 02 08:31:02 2012] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_, referer: http://localhost/Tes.../createHTML.php
[Thu Aug 02 09:13:07 2012] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_/files, referer: http://localhost/Tes.../createHTML.php
[Thu Aug 02 09:14:59 2012] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_/files/w.docx, referer: http://localhost/Tes.../createHTML.php
[Thu Aug 02 09:18:34 2012] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_/files/w.docx/media/word/, referer: http://localhost/Tes.../createHTML.php
[Thu Aug 02 09:19:58 2012] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_/files/w.docx/media, referer: http://localhost/Tes.../createHTML.php
[Thu Aug 02 09:20:27 2012] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_/files/w.docx/media/word, referer: http://localhost/Tes.../createHTML.php
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|