来自URL的Zend_Pdf_Image :: imageWithPath

Pet*_*ter 2 pdf url zend-framework image

我正在使用一个基于URL参数生成PNG图像的脚本image_id.例如:http://www.example.com/image.php?image_id=G554jGTT

现在我想将该图像放在pdf中,如下所示:

$imagepath = "www.example.com/image.php?id=" . $id;
$image = Zend_Pdf_Image::imageWithPath($imagepath);
Run Code Online (Sandbox Code Playgroud)

当我使用本地文件一切顺利,但当我使用URL时,我收到以下错误:

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

有人知道怎么做这个吗?

谢谢!

Mar*_*cin 5

你不能这样做Zend_Pdf_Image::imageWithPath.原因是ImageFacotry期望一个文件.它使用is_file方法来检查文件是否存在.但是,is_file功能不一定适用于远程文件.

解决此问题的一种方法是下载映像并将其保存在临时名称下,然后将此临时文件放入Zend_Pdf_Image::imageWithPath.要下载并保存文件,您可以使用,例如file_put_contents('./tempname',file_get_contents($imagepath)).当然,tempname应该是随机的,之后应该删除它.