我的应用程序应获取图像的快照值并将其上传到特定位置。
在CakePHP之外,此代码可以正常工作,但将其放入控制器后,我得到一个错误:
CSRF令牌不匹配。 Cake \ Http \ Exception \ InvalidCsrfTokenException
HTML:
<input type=button value="Take Snapshot"
onClick="take_snapshot()">
<input type="hidden" name="image" class="image-tag">
PHP:
if ($this->request->is(['post','put',])) {
$img = $_POST['image'];
$folderPath = "C:/upload/";
$image_parts = explode(";base64,", $img);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$fileName = uniqid() . '.jpg';
$file = $folderPath . $fileName;
file_put_contents($file, $image_base64);
print_r($fileName);
}