Created
November 25, 2012 09:20
-
-
Save s-hiroshi/4142915 to your computer and use it in GitHub Desktop.
JavaScript > snippets > Canvasデーターの保存
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function($) { | |
// body部パラメーター | |
var data = {}; | |
// Canvasのデータをbase64でエンコードした文字列を取得 | |
var canvasData = $('canvas').get(0).toDataURL(); | |
// 不要な情報を取り除く | |
canvasData = canvasData.replace(/^data:image\/png;base64,/, ''); | |
data.image = canvasData; | |
$.ajax({ | |
url: 'example.php', | |
type: 'POST', | |
success: function() { | |
// 成功時の処理 | |
}, | |
error(jqXHR, textStatus, errorThrown) { | |
// 失敗時の処理 | |
}, | |
data: data, | |
dataType: 'json' | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$imageData = $_POST['image']; | |
$filename = 'example.png'; | |
$fp = fopen(, 'w'); | |
fwrite($fp,base64_decode($imageData)); | |
fclose($fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment