我不能上傳圖片canvas.toDataURL:我得到警告:不能上傳圖片canvas.toDataURL:在主線程同步的XMLHttpRequest已過時
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/
,然後錯誤:
no element found testSave.php:23:1
在本tutorial,我的JavaScript是:
var canvasData = testCanvas.toDataURL("image/png");
var ajax = new XMLHttpRequest();
ajax.open("POST",'testSave.php',false);
ajax.setRequestHeader('Content-Type', 'application/upload');
ajax.send(canvasData);
和testSave.php:
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
// Get the data
$imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
// Remove the headers (data:,) part.
// A real application should use them according to needs such as to check image type
$filteredData=substr($imageData, strpos($imageData, ",")+1);
// Need to decode before saving since the data we received is already base64 encoded
$unencodedData=base64_decode($filteredData);
//echo "unencodedData".$unencodedData;
// Save file. This example uses a hard coded filename for testing,
// but a real application can specify filename in POST variable
$fp = fopen('test.png', 'wb');
fwrite($fp, $unencodedData);
fclose($fp);
}
?>
你正在嘗試做一個同步的XMLHttpRequest(其已被棄用),並且可能找不到testSave.php。 – jolmos
好吧,它已被棄用,我知道它,但我應該做什麼,而不是上傳這張圖片?文件testSave.php被找到,當我點擊鏈接時,它給我的文件 – Mostafa
如果PHP沒有被執行,那麼你沒有一個Web服務器(或沒有正確配置) – jolmos