在我的PHP FPDF脚本
上<?php
...
$mypdf->Image("http://s3-ap-southeast-1.amazonaws.com/mybucket/path/to/the/image/file.png", null, null, 150, 150);
...
?>
它会导致错误。然而,当我尝试做同样的事情但是在S3上没有托管的不同图像时,它可以工作。
S3如何才能与FPDF一起使用?
答案 0 :(得分:1)
我遇到了同样的问题,经过对fpdf源码的一些挖掘后发现问题出现在fopen()。要将此方法与S3图像一起使用,您需要使用S3 Stream Wrapper。这需要AWS SDK for PHP,否则你也可以自己动手。
我的代码看起来像这样
$credentials = new Aws\Credentials\Credentials('KEY','SECRET');
$client = new Aws\S3\S3Client([
'version'=>'latest',
'region' => 'REGION',
'credentials' => $credentials
]);
$client->registerStreamWrapper();
// Link to file
$url = 's3://bucket/key';
// add background image
$fpdf->Image($url, 0, 0, $fpdf->GetPageWidth(), $fpdf->GetPageHeight());