83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
include '../config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$id_order = $_POST['id_order'];
|
|
$nama_file = $_FILES['bukti_pembayaran']['name'];
|
|
$tmp_file = $_FILES['bukti_pembayaran']['tmp_name'];
|
|
|
|
$folder = '../assets/img/bukti_pembayaran/';
|
|
if (!file_exists($folder)) {
|
|
mkdir($folder, 0777, true);
|
|
}
|
|
|
|
$ext = pathinfo($nama_file, PATHINFO_EXTENSION);
|
|
$nama_baru = 'bukti_' . time() . '.' . $ext;
|
|
|
|
if (move_uploaded_file($tmp_file, $folder . $nama_baru)) {
|
|
// Simpan ke database
|
|
$query = "UPDATE orders SET bukti_pembayaran = '$nama_baru', status_order = 'Menunggu Konfirmasi' WHERE id_order = '$id_order'";
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if ($result) {
|
|
echo "
|
|
<html>
|
|
<head>
|
|
<script src='https://cdn.jsdelivr.net/npm/sweetalert2@11'></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Berhasil!',
|
|
text: 'Bukti pembayaran berhasil diunggah!',
|
|
confirmButtonText: 'OK'
|
|
}).then(() => {
|
|
window.location.href = '../pesanan/index.php?id_order=$id_order';
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>";
|
|
} else {
|
|
echo "
|
|
<html>
|
|
<head>
|
|
<script src='https://cdn.jsdelivr.net/npm/sweetalert2@11'></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Gagal!',
|
|
text: 'Gagal menyimpan ke database.',
|
|
confirmButtonText: 'Kembali'
|
|
}).then(() => {
|
|
window.history.back();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>";
|
|
}
|
|
} else {
|
|
echo "
|
|
<html>
|
|
<head>
|
|
<script src='https://cdn.jsdelivr.net/npm/sweetalert2@11'></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Oops!',
|
|
text: 'Gagal mengunggah file.',
|
|
confirmButtonText: 'Coba Lagi'
|
|
}).then(() => {
|
|
window.history.back();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>";
|
|
}
|
|
}
|
|
?>
|