<?php
    include "koneksi.php";
    $id_akun = $_POST['id_akun_masuk'];
    $random = rand();
    $tmp_file = $_FILES['foto_akun_masuk']['tmp_name'];
    $nama_file = $_FILES['foto_akun_masuk']['name'];
    $format =  array('png', 'jpg', 'jpeg');
    $extensi = pathinfo($nama_file, PATHINFO_EXTENSION);
    if (!in_array($extensi, $format)) {
        header("location: index.php?page=akun&notif=format_gambar_salah");
    } else {
        $file = strtolower(str_replace(" ", "_", $nama_file));
        $file_input = $random.'_'.$file;
        $lokasi_simpan = "assets/img/".$file_input;
        move_uploaded_file($tmp_file, $lokasi_simpan);
        $proses = mysqli_query($koneksi, "UPDATE akun SET foto_akun = '$file_input' WHERE id_akun = '$id_akun'");
        if ($proses) {
            header("location: index.php?page=akun&notif=berhasil_ubah_foto");
        } else {
            echo "Proses Gagal<br>Error : ".$proses."<br>".mysqli_error($koneksi);
        }
    }
?>