upload image dengan canvas

tanya gan:

ane punya coding

Html:

<button id="download_image" class="button small-btn primary-btn upgradeBtn">Download</button>

javascript

<script type="text/javascript">
$("#download_image").click(function(e) {
        e.preventDefault();
        image = canvas.toDataURL();
            $.ajax({
                type: 'POST',
                url: "/save-leader-board",
                contentType: "application/json;",
                dataType: "json",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: {
                    imgBase64: image,
                },
                success: function(data) {
                    alert(data.d);
                },
                error: function(data){
                    alert("fail");
                }
            })
    });
</script>

php.

<?php
$image = $request->imgBase64;  // your base64 encoded
        $image = str_replace('data:image/png;base64,', '', $image);
        $image = str_replace(' ', '+', $image);
        $imageName = str_random(10).'.'.'png';
        \File::put(storage_path(). '/images/' . $imageName, base64_decode($image));
?>

created image di storage berhasil tapi tampilan nya seperti file image corrupt

mohon pencerahnnya gan

avatar echosk
@echosk

64 Kontribusi 1 Poin

Diperbarui 2 tahun yang lalu

2 Jawaban:

<div>Silahkan coba cek thread ini&nbsp;<a href="https://sekolahkoding.com/forum/upload-foto-webcam-ke-database-1642830658">https://sekolahkoding.com/forum/upload-foto-webcam-ke-database-1642830658</a> disitu udah ada contohnya, semoga terbantu.</div>

avatar ahanafi
@ahanafi

815 Kontribusi 554 Poin

Dipost 2 tahun yang lalu

<div>done gan makasih delete code&nbsp;<br><br><br></div><pre>contentType: "application/json;"</pre>

avatar echosk
@echosk

64 Kontribusi 1 Poin

Dipost 2 tahun yang lalu

Login untuk ikut Jawaban