<div class="mb-6">
<div data-hs-file-upload='{
"url": "../../_invoice",
"maxFiles": 1,
"singleton": true
}'>
<template data-hs-file-upload-preview="">
<div class="p-3 bg-white border border-solid border-gray-300 rounded-xl">
<div class="mb-1 flex justify-between items-center">
<div class="flex items-center gap-x-3">
<span class="size-10 flex justify-center items-center border border-gray-200 text-gray-500 rounded-lg" data-hs-file-upload-file-icon="">
<img class="rounded-lg hidden" data-dz-thumbnail="">
</span>
<div>
<p class="text-sm font-medium text-gray-800 ">
<span class="truncate inline-block max-w-[300px] align-bottom" data-hs-file-upload-file-name=""></span>.<span data-hs-file-upload-file-ext=""></span>
</p>
<p class="text-xs text-gray-500" data-hs-file-upload-file-size=""></p>
</div>
</div>
<div class="flex items-center gap-x-2">
<button type="button" class="text-gray-500 hover:text-gray-800 focus:outline-none focus:text-gray-800" data-hs-file-upload-remove="">
<svg class="shrink-0 size-4" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M3 6h18"></path>
<path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"></path>
<path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"></path>
<line x1="10" x2="10" y1="11" y2="17"></line>
<line x1="14" x2="14" y1="11" y2="17"></line>
</svg>
</button>
</div>
</div>
<div class="flex items-center gap-x-3 whitespace-nowrap">
<div class="flex w-full h-2 bg-gray-200 rounded-full overflow-hidden" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" data-hs-file-upload-progress-bar="">
<div class="flex flex-col justify-center rounded-full overflow-hidden bg-blue-600 text-xs text-white text-center whitespace-nowrap transition-all duration-500 hs-file-upload-complete:bg-green-500" style="width: 0" data-hs-file-upload-progress-bar-pane=""></div>
</div>
<div class="w-10 text-end">
<span class="text-sm text-gray-800 ">
<span data-hs-file-upload-progress-bar-value="">0</span>%
</span>
</div>
</div>
</div>
</template>
<div class="cursor-pointer p-12 flex justify-center bg-white border border-dashed border-gray-300 rounded-xl" data-hs-file-upload-trigger="">
<div class="text-center">
<span class="inline-flex justify-center items-center size-16 bg-gray-100 text-gray-800 rounded-full">
<svg class="shrink-0 size-6" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
<polyline points="17 8 12 3 7 8"></polyline>
<line x1="12" x2="12" y1="3" y2="15"></line>
</svg>
</span>
<div class="mt-4 flex flex-wrap justify-center text-sm leading-6 text-gray-600">
<span class="pe-1 font-medium text-gray-800">
Drop your file here or
</span>
<span class="bg-white font-semibold text-blue-600 hover:text-blue-700 rounded-lg decoration-2 hover:underline focus-within:outline-none focus-within:ring-2 focus-within:ring-blue-600 focus-within:ring-offset-2">browse</span>
</div>
<p class="mt-1 text-xs text-gray-400">
Pick a file up to 2MB.
</p>
</div>
</div>
<div class="mt-4 space-y-2 empty:mt-0" data-hs-file-upload-previews=""></div>
</div>
</div>
<?php
if (isset($_POST['add'])) {
$user = $_SESSION['iduser'];
$user_name = $_SESSION['fullname'];
// Validate and process the form data
$idproj = $_POST['idproj'];
$supplier = $_POST['supplier'];
$phoneno = isset($_POST['phone']) ? mysqli_real_escape_string($conn, $_POST['phone']) : null;
$email = isset($_POST['email']) ? mysqli_real_escape_string($conn, $_POST['email']) : null;
$company = isset($_POST['company']) ? mysqli_real_escape_string($conn, $_POST['company']) : null;
$address = isset($_POST['address']) ? mysqli_real_escape_string($conn, $_POST['address']) : null;
$serv = $_POST['services'];
$desc = isset($_POST['desc']) ? mysqli_real_escape_string($conn, $_POST['desc']) : null;
// Initialize the $target_file variable
$target_file = null;
// Check if the invoice file was uploaded
if (isset($_FILES['invoice']) && $_FILES['invoice']['error'] === UPLOAD_ERR_OK) {
$pdf_file = $_FILES['invoice'];
// Check if file is a PDF
$file_type = mime_content_type($pdf_file['tmp_name']);
if ($file_type != 'application/pdf') {
die("Only PDF files are allowed.");
}
// Upload directory
$upload_dir = "../../_invoice/";
if (!is_dir($upload_dir)) {
if (!mkdir($upload_dir, 0777, true)) {
die('Failed to create directories...');
}
}
// Generate a unique name for the file and move it to the upload directory
$file_name = "SupInv_" . uniqid() . "_" . basename($pdf_file['name']);
$target_file = $upload_dir . $file_name;
if (!move_uploaded_file($pdf_file['tmp_name'], $target_file)) {
echo "Error uploading the file.";
$target_file = null; // Reset $target_file to null if upload fails
}
}
// Build the SQL query based on whether the invoice was uploaded
if ($target_file) {
$sql = "INSERT INTO supplier (idproj, suppliername, suppliernotel, supplieremail, companyname, companyaddress, services, servicesdesc, invoicepdf, supplierCreated, created_by)
VALUES ('$idproj', '$supplier', '$phoneno', '$email', '$company', '$address', '$serv', '$desc', '$target_file', '$user_name', '$user')";
} else {
$sql = "INSERT INTO supplier (idproj, suppliername, suppliernotel, supplieremail, companyname, companyaddress, services, servicesdesc, supplierCreated, created_by)
VALUES ('$idproj', '$supplier', '$phoneno', '$email', '$company', '$address', '$serv', '$desc', '$user_name', '$user')";
}
$execute = mysqli_query($conn, $sql);
if ($execute) {
echo "<script>
const Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
Toast.fire({
icon: 'success',
title: 'New Supplier Added Successfully',
text: 'Redirecting . . . '
}).then(() => {
window.location.href = '../project/vendor.php';
});
</script>";
// Notification
$newidsupplier = mysqli_insert_id($conn);
$iduser = $_SESSION["iduser"];
$noti = "INSERT INTO notiadd (description, iduser, idsupplier)
VALUES
('New Vendor Added', '$iduser', '$newidsupplier')";
$sqlnoti = mysqli_query($conn, $noti);
} else {
echo "Error: " . mysqli_error($conn);
}
}?>
currently im working on new ui for uploading file. before this im using normal input file so there is no problem at all. but this time im using preline library file upload. the thing is the file i upload is not detect because obviously not have input tag. but now i dont know how and where to put it. if i put it inside the code it seems the input and the file upload not sync and uploading empty data to my database. help me to find the solution