0
我正在使用以下腳本將html canvas轉換爲png,並讓客戶端下載它而不將圖像保存到服務器。這些腳本在xampp中以及在cuccfree.cc服務器上工作。但是相同的腳本在我需要託管的服務器中不起作用。base64解碼圖像不下載
的Javascript
fname = fname || 'picture';
var data = cnvs.toDataURL("image/png");
data = data.substr(data.indexOf(',') + 1).toString();
var dataInput = document.createElement("input") ;
dataInput.setAttribute("name", 'imgdata') ;
dataInput.setAttribute("value", data);
dataInput.setAttribute("type", "hidden");
var nameInput = document.createElement("input") ;
nameInput.setAttribute("name", 'name') ;
nameInput.setAttribute("value", fname + '.png');
var myForm = document.createElement("form");
myForm.method = 'post';
myForm.action = url;
myForm.appendChild(dataInput);
myForm.appendChild(nameInput);
document.body.appendChild(myForm) ;
myForm.submit() ;
document.body.removeChild(myForm) ;
PHP素文字
<?php
# we are a PNG image
header('Content-type: image/png');
# we are an attachment (eg download), and we have a name
header('Content-Disposition: attachment; filename="' . $_POST['name'] .'"');
#capture, replace any spaces w/ plusses, and decode
$encoded = $_POST['imgdata'];
$encoded = str_replace(' ', '+', $encoded);
$decoded = base64_decode($encoded);
#write decoded data
echo $decoded;
?>
但這是輸出我得到當我被分配到JavaScript函數的按鈕點擊。 http://oi57.tinypic.com/2je1cva.jpg
我該如何糾正這個錯誤?請幫助我....