[PHP] 캔버스 이미지 업로드

2020. 6. 23. 17:00PHP

// 웹캠 사용하기 참고글 https://ddochi-dev.tistory.com/entry/HTML-%EC%9B%B9%EC%BA%A0-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0

// script
<script>
document.getElementById("webcamBtn").addEventListener("click",function() {
	context.drawImage(video,0,0,960,720);
	$.ajax({
		type : 'post',
		data: {
			file: canvas.toDataURL()
		},
		success:function(data) {
		}
	});
});
</script>

// PHP
$file = $_POST['file'];
list($type, $file) = explode(';',$file);
list(,$file) = explode(',',$file);
$file = base64_decode($file);
$filename = "파일명.jpg";
$savedir = "파일경로";
file_put_contents("{$savedir}{$filename}",$file);

'PHP' 카테고리의 다른 글

[PHP] flush를 이용한 디버그 메세지 출력  (0) 2020.04.03
[PHP] 메모리 무제한 설정  (0) 2020.04.03
[PHP] base64 데이터를 이미지로 저장하기  (0) 2020.03.20
[PHP] 유튜브 API  (0) 2020.03.20
[PHP] 공휴일 API  (0) 2020.03.20