Re: [請益] HELP!!! 關於 FPDF 崁入圖片>"<
※ 引述《teaRsis (就是喜歡找「茶」)》之銘言:
: Q:請問如何在FPDF中支援外連圖片的崁入?
: 目前在做一個系統
: 經過ABC步驟後可以產生結果D
: D的開頭有用 session_start();
: 以擷取ABC傳的值來顯示結果
: D中有做一個按鈕「存成PDF」
: 是把D的結果重整後透過FPDF來轉存PDF
: D的顯示結果我有使用GOOGLE的API
: http://is.gd/g4xmU
: 點選以上網址會變為原本的網址
: http://chart.apis.google.com/chart?xxxxxxbalabala
: 它是個PNG檔 但結尾不是PNG
: 重點來了
: FPDF中要崁入圖片
: 是使用以下語法
: $pdf->Image('chart.png', 5, 30, 60, 50);
: 但是它無法支援外連圖片
: 我有想過使用暫存檔將圖片強制崁入
: 而且那一串長長的網址也不是PNG結尾
: 好像不太行的說
: 不知各位高手可否提供一些意見
: 謝謝!
→
10/17 00:11,
10/17 00:11
→
10/17 00:12,
10/17 00:12
我上網查到資料
http://phorum.study-area.org/index.php?topic=61508.0
按照裡面方式寫一個簡單PHP
header("Content-type: image/png");
$url="http://chart.apis.google.com/chart?cht=gom&chd=t:100&chl=0&chs=340x230";
$picture = file_get_contents($url);
echo $picture;
可以在網頁上印出圖片
不過把他寫到FPDF的網頁中就還是印不出來
<?
define('FPDF_FONTPATH',"fpdi134/font/");
//引入函式庫
// require("fpdi134/fpdf.php");
require_once ('fpdi134/fpdf.php');
require_once ('fpdi134/fpdf_tpl.php');
require_once ('fpdi134/chinese-unicode.php');
require_once ('fpdi134/fpdi.php');
header("Content-type: image/png");
$url="http://chart.apis.google.com/chart?cht=gom&chd=t:100&chl=0&chs=340x230";
$picture = file_get_contents($url);
$pdf=new PDF_Unicode();
$pdf->Open();
$pdf->SetTitle("檢測結果");//文件標題
$pdf->SetAuthor("NCKUID");//文件作者
$pdf->AddPage();
$pdf->SetAutoPageBreak(true,10);
$pdf->AddUniCNShwFont('uni');
$pdf->Image($picture,45,4,19.5,0,'png');
$filename = "test.pdf";//pdf檔名
//header
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename=$filename");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
$pdf->Output("test.pdf", 'D');//產生下載檔
?>
但是他會出現錯誤訊息:無法顯示錯誤的圖片
一定要存到資料庫在取出才行嗎??
關於存圖片到資料庫
網路上的教學都是用 upload 一個桌面上的檔案
http://forum.twbts.com/thread-581-1-1.html
不知道怎樣可以改成上傳外連的圖片??
高手們麻煩給些建議
謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.134.139
※ 編輯: teaRsis 來自: 140.116.134.139 (10/18 12:52)
※ 編輯: teaRsis 來自: 140.116.134.139 (10/18 12:53)
→
10/18 13:25, , 1F
10/18 13:25, 1F
→
10/18 15:56, , 2F
10/18 15:56, 2F
→
10/18 15:56, , 3F
10/18 15:56, 3F
→
10/18 15:57, , 4F
10/18 15:57, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章