的JavaScript:阿賈克斯發送POST和發送帆布
var username = 'sami';
var myImage = canvas.toDataURL("image/png");
var ajax = new XMLHttpRequest();
ajax.open("POST", "Pic.php", false);
ajax.setRequestHeader('Content-Type', 'application/upload');
ajax.send(myImage);
ajax.send("q=" + encodeURIComponent(username));
PHP:
<? php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
$user = $_POST['q'];
$comp = $user.".png";
$imageData = $GLOBALS['HTTP_RAW_POST_DATA'];
$filteredData = substr($imageData, strpos($imageData, ",") + 1);
$unencodedData = base64_decode($filteredData);
$fp = fopen($comp, 'wb');
fwrite($fp, $unencodedData);
fclose($fp);
} ?>
這是代碼,問題是,我無法用後,得到了用戶的時候圖像保存它的「.png」只...