我創建使用PHP條碼插件如何將條形碼圖像保存到計算機驅動器中的文件夾?
HTML
<img src="barcode.php?codetype=Code128&size=50&text=123421321321321321" style="width:auto; height:auto;" alt="123456789"/>
我怎麼能這個條碼圖像保存到本地驅動器的硬盤驅動器的條形碼?
我創建使用PHP條碼插件如何將條形碼圖像保存到計算機驅動器中的文件夾?
HTML
<img src="barcode.php?codetype=Code128&size=50&text=123421321321321321" style="width:auto; height:auto;" alt="123456789"/>
我怎麼能這個條碼圖像保存到本地驅動器的硬盤驅動器的條形碼?
試試這個獲取內容,並保存到文件
$barcode = file_get_contents('http://www.youdomain.com/barcode.php?codetype=Code128&size=50&text=123421321321321321');
//you can also use below function get more info on image
//$imgInfo = getimagesize($barcode);
//save the file to disk
file_put_contents('path_to_file/code.png', $barcode);
使用捲曲
//You can also try it using CURL if above doesn't works
$ch = curl_init('http://www.youdomain.com/barcode.php?codetype=Code128&size=50&text=123421321321321321');
$fp = fopen('path_to_file/code.png', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
編輯barcode.php
現在,它很簡單,在文件它只是簡單地返回圖像的標題,就在您添加此行以將其保存在服務器上之前
// Save the image to file.png
imagepng($image, "file.png"); // Your barcode will be saved here with name file.png
// Draw barcode to the screen
header ('Content-type: image/png');
imagepng($image);
imagedestroy($image);
希望這有助於
運行你的代碼後我得到錯誤 –
什麼錯誤,請發帖 – Saqueib
我的目的是想將圖像自動保存到磁盤,不需要提示信息保存框。警告:file_get_contents(barcode.php?codetype = Code128&size = 50&text = 123421321321321321)[function.file-get-contents]:未能打開流:在D:\ wamp \ www \ SVN \ roadTax \ doc中沒有這樣的文件或目錄。 php 12行 –
請發表您的'barcode'創建代碼,以便更好地理解。 –
右鍵單擊 - >保存到磁盤?你在問什麼?你實際上看到了什麼'barcode.php'? – h2ooooooo
呃......對不起,我的意思是當頁面加載時如何保存條碼圖像自動。 –