13 Replies - 3226 Views - Last Post: 01 August 2012 - 06:23 PM Rate Topic: -----

#1 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

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??

<?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";
}
?>



Is This A Good Question/Topic? 0
  • +

Replies To: PHPDocx not displaying images when a docx file with image is converted

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3034
  • View blog
  • Posts: 10,581
  • Joined: 08-August 08

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?
Was This Post Helpful? 0
  • +
  • -

#3 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

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?
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3034
  • View blog
  • Posts: 10,581
  • Joined: 08-August 08

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:

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.
Was This Post Helpful? 0
  • +
  • -

#5 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

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..
Was This Post Helpful? 0
  • +
  • -

#6 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

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
Was This Post Helpful? 0
  • +
  • -

#7 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

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?
Was This Post Helpful? 0
  • +
  • -

#8 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

Re: PHPDocx not displaying images when a docx file with image is converted

Posted 26 July 2012 - 07:05 PM

View PostDuckington, on 26 July 2012 - 01:11 AM, said:

Does that directory exist? Do you have permissions to write to it?


No it doesn't exists. But I thought phpdocx will make that automatically because a directory name is same as the file
Was This Post Helpful? 0
  • +
  • -

#9 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

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.
Was This Post Helpful? 0
  • +
  • -

#10 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

Re: PHPDocx not displaying images when a docx file with image is converted

Posted 27 July 2012 - 02:55 AM

View PostDuckington, 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.
Was This Post Helpful? 0
  • +
  • -

#11 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

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).
Was This Post Helpful? 1
  • +
  • -

#12 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

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...
Was This Post Helpful? 0
  • +
  • -

#13 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,546
  • Joined: 23-August 08

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

C:/wamp/www/Testing Site/Tiny MCE UPLOAD AND SAVE TESTING/Test 4/phpdocx_free/examples/easy/files/files_


actually exist?
Was This Post Helpful? 0
  • +
  • -

#14 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

Re: PHPDocx not displaying images when a docx file with image is converted

Posted 01 August 2012 - 06:23 PM

View PostJackOfAllTrades, on 01 August 2012 - 05:57 PM, said:

Well, do all the directories listed in this path

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1