→ LewisHamiltn:把圖片抓下來另存...10/17 00:11
→ LewisHamiltn:看你是要用file_get_contents, curl, wget都可以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)
→ kylekai:送了兩個 Header ?.. 先搞清楚抓圖片下來的作法. 10/18 13:25
→ LewisHamiltn:我沒看你那個pdf的manual不過顯然他要的參數是"檔名" 10/18 15:56
→ LewisHamiltn:而你把圖片的binary內容丟給他 想當然是不會成功的 10/18 15:56
→ LewisHamiltn:請把binary內容存成本地端檔案再傳檔名給pdf class 10/18 15:57