| Server IP : 3.111.61.48 / Your IP : 216.73.216.67 Web Server : Apache System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.2.31 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/vhost/itms.arukustech.com/public/api/ |
Upload File : |
<?php
header("Content-Type: application/json");
require_once __DIR__ . '/../../app/db.php';
$pdo = db();
/* Validate item ID */
if (!isset($_POST['item_id'])) {
echo json_encode(["status" => "error", "message" => "Missing item ID"]);
exit;
}
$item_id = intval($_POST['item_id']);
/* Validate file */
if (!isset($_FILES['invoice_file']) || $_FILES['invoice_file']['error'] !== 0) {
echo json_encode(["status" => "error", "message" => "No valid file uploaded"]);
exit;
}
/* Create MAIN invoice folder (NO ITEM SUBFOLDER) */
$uploadDir = __DIR__ . '/../../public/uploads/invoices/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
/* Generate unique filename */
$ext = strtolower(pathinfo($_FILES['invoice_file']['name'], PATHINFO_EXTENSION));
$filename = "invoice_" . $item_id . "_" . time() . "." . $ext;
$serverPath = $uploadDir . $filename;
/* Move file to server */
if (!move_uploaded_file($_FILES['invoice_file']['tmp_name'], $serverPath)) {
echo json_encode(["status" => "error", "message" => "File upload failed"]);
exit;
}
/* PUBLIC URL (Browser-accessible path) */
$publicUrl = "/uploads/invoices/" . $filename;
/* Update DB */
$stmt = $pdo->prepare("UPDATE inventory_items SET invoice_file = ? WHERE id = ?");
$stmt->execute([$publicUrl, $item_id]);
echo json_encode([
"status" => "success",
"message" => "Invoice uploaded successfully",
"invoice_file" => $publicUrl
]);
?>