2016-12-14 17 views
0

我需要獲取帆布數據,並使用PHP對其進行解碼隱蔽吧,我的代碼如下:如何獲得畫布上的數據和使用PHP

<canvas id="canvas" name="canvas" class="img-responsive thumbnail" style="margin-bottom:9px;"></canvas> 
<?php 
    $dataURL=$_POST['canvas']; 
?> 

在這裏,我需要將其轉換成toDataURL()並保存到服務器。沒有AJAX調用可能嗎?

請幫幫我。

+0

所以你想保存畫布作爲圖像在服務器上? – Ionut

回答

0

如果你想你的畫布圖像保存到你必須使用AJAX的服務器,你不僅可以在PHP中做到這一點:

var url = canvas.toDataURL(); 
$.ajax({ 
    type: "POST", 
    url: "canvas_save.php", 
    data: { 
    imageToSave: url 
    }, 
    success: function(response){ 

    } 
}); 

而且在你的PHP腳本canvas_save.php,那麼你將有:

$dataURL = $_POST['imageToSave']; 
$decoded_image = base64_decode($dataURL); 
file_put_contents('full_path_including_file_name_and_extension', $decoded_image); 
相關問題