2016-04-25 79 views
0

我正在使用tcpdf生成PDF報告。我想在PDF報告上打印圖像,但是我有圖像的URL,例如: https://myserver.com/media/4410/field.jpgTcpdf使用URL顯示圖像

當我在tcpdf的Image()函數中使用它時。它不顯示任何圖像。 圖像不在我運行我的PHP腳本生成PDF報告的同一臺服務器上。 如何訪問這些圖像並將其顯示在PDF上。爲什麼網址無效。請建議。我究竟做錯了什麼。

+0

也許你可以使用'$圖像=的file_get_contents插入圖像( 'http://example.com/image.jpg');' – Peter

回答

1

你可以在你的臨時文件夾在本地存儲圖像:

$image = @file_get_contents('http://www.example.com/image.jpg'); 

if ($image != '') { 
    $filename = uniqid.'.jpg'; 
    file_put_contents('/tmp/'.$filename, $image); 
} 

// You can now insert your image using the $filename variable 
$pdf->image('/tmp/'.$filename);