开发者

Zend_Pdf_Image::imageWithPath from URL

I'm using a script that generates a PNG image based on a URL parameter image_id. For example: http://www.example.com/image.php?image_id=G554jGTT

Now I want to place that image in a pdf like so:

$imagepath = "www.example.com/image.php?id=" . $id;
$image = Zend_Pdf_Image::imageWithPath($imagepath);

When I use a local file all goes well, but when I use an URL I get the following error:

Fatal error: Uncaught exception 'Zend_Pdf_Exception' with message 'Cannot create image resource. File not found.' in E:<...>\library\Zend\Pdf\Resource\ImageFactory.php:38

Doe开发者_JS百科s anybody know how to do this?

Thanks!


You cannot do this using Zend_Pdf_Image::imageWithPath. The reason is that the ImageFacotry expects a file. And it uses is_file method to check if file exists. However, is_file function does not necessarily work with remote files.

One way to overcome this problem would be to download the image and save it under temporary name, and this temporary file then put into Zend_Pdf_Image::imageWithPath. To download and save the file, you could use, e.g. file_put_contents('./tempname',file_get_contents($imagepath)). Off course, the tempname should be random and it should be removed afterwards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜