update cara upload gambar
This commit is contained in:
+62
-1
@@ -120,7 +120,68 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
echo json_encode(['success' => false, 'error' => 'Mikrotik tidak terhubung']);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
elseif ($tabel === 'tagihan') {
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
a.id,
|
||||
a.transaction_id,
|
||||
a.transaction_data,
|
||||
b.apikey_payment_gateway,
|
||||
b.url_payment_gateway
|
||||
FROM
|
||||
tagihan a
|
||||
LEFT JOIN
|
||||
data_server b
|
||||
ON a.id_data_server = b.id
|
||||
WHERE
|
||||
a.id = :id
|
||||
AND a.transaction_id != ''
|
||||
AND a.transaction_status = 'ACTIVE'
|
||||
AND a.transaction_data != ''
|
||||
AND b.payment_gateway = 'flip'
|
||||
AND b.status_payment_gateway = 'ACTIVE'
|
||||
";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([':id' => $id]);
|
||||
$data = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($data && !empty($data['transaction_data'])) {
|
||||
require "../payment/flip/Flip/Transaction.php";
|
||||
|
||||
$data2 = json_decode($data['transaction_data'], true);
|
||||
if (json_last_error() === JSON_ERROR_NONE && !empty($data2['link_id'])) {
|
||||
$flip = new FlipPaymentGateway($data['apikey_payment_gateway'], $data['url_payment_gateway']);
|
||||
|
||||
$flip->editBill(
|
||||
$data2['link_id'],
|
||||
'INACTIVE',
|
||||
$data2['title'] ?? '',
|
||||
$data2['amount'] ?? 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM tagihan WHERE id = ?";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindParam(1, $id, PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$deletedCount = $stmt->rowCount();
|
||||
$response = [
|
||||
'success' => true,
|
||||
'deleted_count' => $deletedCount,
|
||||
'deleted_items' => [
|
||||
['table' => 'data yang anda hapus', 'count' => $deletedCount]
|
||||
]
|
||||
];
|
||||
} else {
|
||||
$response = ['success' => false, 'error' => 'Gagal menghapus data'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Menyiapkan perintah SQL untuk menghapus data dari tabel lain
|
||||
$sql = "DELETE FROM $tabel WHERE id = ?";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
+71
-16
@@ -46,53 +46,108 @@ function minioUpload($bucket, $key, $sourceFile) {
|
||||
/**
|
||||
* Upload lokal dan MinIO
|
||||
*/
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
||||
if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
|
||||
|
||||
$uploadDir = '../img/user/';
|
||||
if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);
|
||||
session_start(); // pastikan session aktif
|
||||
|
||||
$fileExt = "." . pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
|
||||
$fileName = "bilspro_" . date('YmdHis') . $fileExt;
|
||||
$uploadFile = $uploadDir . $fileName;
|
||||
$formId = $_POST['formId'];
|
||||
|
||||
// --- 1️⃣ Upload ke server lokal ---
|
||||
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
|
||||
// --- 📤 Upload langsung ke MinIO ---
|
||||
$tmpFilePath = $_FILES['file']['tmp_name']; // ambil file temporary upload
|
||||
|
||||
// --- 2️⃣ Upload ke MinIO ---
|
||||
$minioUrl = minioUpload('files', 'user/' . $fileName, $uploadFile);
|
||||
// Pastikan minioUpload menerima path file lokal sementara ($tmpFilePath)
|
||||
$minioUrl = minioUpload('files', 'user/' . $fileName, $tmpFilePath);
|
||||
|
||||
if ($minioUrl) {
|
||||
// Simpan info file ke session
|
||||
if (!isset($_SESSION['uploaded_files'])) {
|
||||
$_SESSION['uploaded_files'] = [];
|
||||
}
|
||||
|
||||
$_SESSION['uploaded_files'][$formId] = $fileName;
|
||||
|
||||
// $_SESSION['uploaded_files'][$formId] = [
|
||||
// 'local' => $fileName,
|
||||
// 'minio' => $minioUrl ?: null
|
||||
// 'file_name' => $fileName,
|
||||
// 'minio_url' => $minioUrl
|
||||
// ];
|
||||
|
||||
// --- Respons sukses ---
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'File berhasil diupload.',
|
||||
'local_path' => $uploadFile,
|
||||
'file_name' => $fileName,
|
||||
'minio_url' => $minioUrl
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal upload ke server lokal.']);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal upload.'
|
||||
]);
|
||||
}
|
||||
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Tidak ada file diupload atau terjadi error.']);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Tidak ada file diupload atau terjadi error.'
|
||||
]);
|
||||
}
|
||||
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Invalid request method.']);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Invalid request method.'
|
||||
]);
|
||||
}
|
||||
|
||||
// if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
||||
// if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
|
||||
|
||||
// $uploadDir = '../img/user/';
|
||||
// if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);
|
||||
|
||||
// $fileExt = "." . pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
|
||||
// $fileName = "bilspro_" . date('YmdHis') . $fileExt;
|
||||
// $uploadFile = $uploadDir . $fileName;
|
||||
// $formId = $_POST['formId'];
|
||||
|
||||
// // --- 1️⃣ Upload ke server lokal ---
|
||||
// if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
|
||||
|
||||
// // --- 2️⃣ Upload ke MinIO ---
|
||||
// $minioUrl = minioUpload('files', 'user/' . $fileName, $uploadFile);
|
||||
|
||||
// // Simpan info file ke session
|
||||
// if (!isset($_SESSION['uploaded_files'])) {
|
||||
// $_SESSION['uploaded_files'] = [];
|
||||
// }
|
||||
|
||||
// $_SESSION['uploaded_files'][$formId] = $fileName;
|
||||
// // $_SESSION['uploaded_files'][$formId] = [
|
||||
// // 'local' => $fileName,
|
||||
// // 'minio' => $minioUrl ?: null
|
||||
// // ];
|
||||
|
||||
// // --- Respons sukses ---
|
||||
// echo json_encode([
|
||||
// 'status' => 'success',
|
||||
// 'message' => 'File berhasil diupload.',
|
||||
// 'local_path' => $uploadFile,
|
||||
// 'minio_url' => $minioUrl
|
||||
// ]);
|
||||
// } else {
|
||||
// echo json_encode(['status' => 'error', 'message' => 'Gagal upload ke server lokal.']);
|
||||
// }
|
||||
|
||||
// } else {
|
||||
// echo json_encode(['status' => 'error', 'message' => 'Tidak ada file diupload atau terjadi error.']);
|
||||
// }
|
||||
|
||||
// } else {
|
||||
// echo json_encode(['status' => 'error', 'message' => 'Invalid request method.']);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user