Forum


Replies: 9   Views: 4540
Cannot find image
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by jc.021286  · 10-09-2014 - 22:36

I seem to be having issues with finding images. If I use the absolute path, i cannot get the image. Though if I use a relative path '../../img/example.jpg' I can find it. I am not sure if this is related to the following issue. However, when I try to source an image from a dynamic script: "http://www.officedocumentconsulting.com/main_php/upload_images_display.php?instance=0123456789b&floor=557&state=0.jpg" it cannot find it. Is it because the image is displayed through PHP as it is calling it from a database. Navigating to the URL in the browser pulls up the image just fine. Using the relative path which resolved the absolute image reference that resolved the earlier issue, does not work in this instance. This did work however when using the function with the now depreciated: $docx->addTemplateVariable('IMAGE_'.$i, $PHP_SCRIPT_TO_IMAGE, 'image', '440', '440');

Posted by jc.021286  · 11-09-2014 - 04:53

After digging through the createDocx.inc for the past 9 hours. I seem to have found several things. 1. I can add an image from a known URL with a relative path (ex: '../../images/10.jpg') Though when i use the absolute path (ex: 'www....' or 'http://....' or 'https://...' this will throw errors) 2. working through the things. I can forcefully get the CreateDocx.inc => AddImage to add my image and finish that subroutine. THough later on, I get a: DOMDocument::loadXML(): EntityRef: expecting ';' in Entity, line:2 in /.../classes/AutoLoader.inc(64) :eval()'d code is the program looking for the URL to be escaped of ampersands? or it does not like multiple periods in the URL. Any assistance in this matter will help with moving us towards upgrading from pro to corporate if successful. This would also mean that our customers who want to run our software on their own servers would need pro licenses as well. So it would help with getting multiple corporate or enterprise licenses lined up in the next 6-12 months.

Posted by admin  · 11-09-2014 - 07:59

Hello, We see you're using the trial version. Sorry but as the trial package is crypted is impossible to know where is the error. I recommend you to upgrade at least to the PRO license. Regards.

Posted by jc.021286  · 11-09-2014 - 14:53

I am on 3.7 Pro +. I was trying the 4.0 trial. Can I have you use your current version / trial version and see if it is an extensive issue to have something like: http://www.officedocumentconsulting.com/main_php/upload_images_display.php?instance=0123456789b&floor=557&state=0.jpg Inserted into a table or not?

Posted by admin  · 11-09-2014 - 15:18

Hello, The best approach could be to get the image using curl and then add it as any other image. This is get it, save to the disk and add it. You can get the image using curl using a code like: $ch = curl_init ($imageUrl); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $raw = curl_exec($ch); $fp = fopen($pathImage,'x'); fwrite($fp, $raw); fclose($fp); Regards.

Posted by jc.021286  · 11-09-2014 - 15:27

Could you please explain what is happening? I do not see where you add the image to the $docx=> ...add?... If you mean that the user is to have multiple downloads start for every image and they must manually place into the file, I do not see that working for "automation"

Posted by admin  · 12-09-2014 - 07:03

Hello, The embedHtml method allows to download the images from an URL, but the addImage needs that they exist in the file system. So there's no option but download them before adding them to the document. Regards.

Posted by jari.heinonen  · 29-12-2014 - 08:24

Hi, Is it (still) possbile to retrieve the image from a DB and place it into the docx document without creating first a file into the file system? We are currently trying to upgrade to phptodocx 4.1 but images causes us quite a headache. In 3.7 we were able to retrieve images (photos) directly from the db and place them on the docx. But with 4.1. our code below does not work anymore. Please, could you please give us a hint what to do? // $photos array is retrieved from the database foreach ($photos as $photo) { $imageElement = addImage($photo, true, $this->imageSize); $col1['value'] = createWordMLFragment(array($imageElement)); $col2['value'] = ... $imageTable[] = array($col1, $col2); // The MS word table will have images per table row addTable($imageTable, $imageTableProperties, $imageRowProperties); .... In 4.1 documentation there are plenty of examples for handling image file from the file system. When testing with image files all other parts of our code works OK. For us it would be much more convenient to retrieve images directly from database. $photo = 'photo1.jpg' $paramsImg = array( 'src' => $photo, ...... (other parameters)); $imageFragment = new WordFragment($this->document); $imageFragment->addImage($paramsImg); ..

Posted by admin  · 30-12-2014 - 10:18

Hello, Which method did you use with phpdocx 3.7 to add the images from the database? Both phpdocx 4 and phpdocx 3 uses the function file_exists in the addImage method, so they need the image to exists as file. Regards.

Posted by jari.heinonen  · 02-01-2015 - 07:16

Hi, Thanks for your reply. After more detailed analysis, I found that the file output is indeed utilized. I was confused by the overloaded AddImage method that the team had used. This was completely my mistake that was caused by a "blind eye" syndome.