1$path = 'myfolder/myimage.png';
2$type = pathinfo($path, PATHINFO_EXTENSION);
3$data = file_get_contents($path);
4$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
5
1$img = $_POST['img'];
2$img = str_replace('data:image/png;base64,', '', $img);
3$img = str_replace(' ', '+', $img);
4$data = base64_decode($img);
5$file = "images/" . uniqid() . '.png';
6$success = file_put_contents($file, $data);