Quantcast
Channel: PHPWord
Viewing all articles
Browse latest Browse all 450

Commented Issue: How to add image from url? [52]

$
0
0

Hello!

I try add image from my site (http://mysite/image.php).
code:

```
<?php
require_once '../PHPWord.php';
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$section->addMemoryImage('http://mysite/image.php');//<---
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('Image.docx');
?>

```

___Fatal error: Uncaught exception 'Exception' with message 'Could not close zip file Image.docx.' in /PHPWord_0.6.2_Beta/PHPWord/Writer/Word2007.php:158
Stack trace: #0 /PHPWord_0.6.2_Beta/Examples/Image.php(36):
PHPWord_Writer_Word2007->save('Image.docx') #1 {main} thrown in/PHPWord_0.6.2_Beta/PHPWord/Writer/Word2007.php on line 158___

When I use: __$section->addImage('image.jpg');__ script it works.

Can you help me please.
Thanks for your answer.
Comments: addMemoryImage() is meant for PHP generated images, such as those created or modified by the GD library, or its analogs. If you're up for handling your file types on your own JPG,GIF and PNG, this would probably help: http://www.php.net/manual/en/function.imagecreatefromjpeg.php#22783 It shows how to use imagecreatefromjpeg() to fetch the image data from a URL via "fopen()" using a temp file until loaded into memory via the "$imageData = LoadJPEG("http://www.example.com/example.jpg");" call. Your next step should be "addMemoryImage($imageData,........." cURL is just as capable of handling the transmission.

Viewing all articles
Browse latest Browse all 450

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>