尝试发送canvas
at Blob
; javascript
使用fopen()
with作为参数来php://input
读取Blob
或处理文件stream_copy_to_stream
file_get_contents()
file_put_contents()
php
看HTMLCanvasElement.toBlob()
if (!HTMLCanvasElement.prototype.toBlob) {
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
value: function (callback, type, quality) {
var binStr = atob( this.toDataURL(type, quality).split(',')[1] ),
len = binStr.length,
arr = new Uint8Array(len);
for (var i=0; i<len; i++ ) {
arr[i] = binStr.charCodeAt(i);
}
callback( new Blob( [arr], {type: type || 'image/png'} ) );
}
});
}
超越 $_POST、$_GET 和 $_FILE:在 JavaScript 和 PHP 中使用 Blob
<?php
// choose a filename
$filename = "hello.json";
// the Blob will be in the input stream, so we use php://input
$input = fopen('php://input', 'rb');
$file = fopen($filename, 'wb');
// Note: we don't need open and stream to stream, we could've used file_get_contents and file_put_contents
stream_copy_to_stream($input, $file);
fclose($input);
fclose($file);
?>