500000) { echo json_encode(["error" => "Ukuran file terlalu besar."]); exit; } // Cek format file if (!in_array($imageFileType, ["jpg", "png", "jpeg", "gif"])) { echo json_encode(["error" => "Hanya file JPG, JPEG, PNG & GIF yang diperbolehkan."]); exit; } // Upload file if (move_uploaded_file($_FILES["profile"]["tmp_name"], $target_file)) { // Simpan nama file baru ke database $id = $_SESSION['agen']; $sql = "UPDATE agen_voucher SET profile = '$new_file_name' WHERE id = $id"; if ($con->query($sql) === TRUE) { echo json_encode(["success" => "Profile telah diubah."]); } else { echo json_encode(["error" => "Error: " . $sql . "
" . $con->error]); } } else { echo json_encode(["error" => "Terjadi kesalahan saat mengunggah file."]); } } ?>