From 5eaef3952350cedfca794a853027bdd6e1c239eb Mon Sep 17 00:00:00 2001 From: dyzulk <66510723+dyzulk@users.noreply.github.com> Date: Sun, 4 Jan 2026 22:40:24 +0700 Subject: [PATCH] chore: add specific attachment debug tool --- debug-attachment.php | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 debug-attachment.php diff --git a/debug-attachment.php b/debug-attachment.php new file mode 100644 index 0000000..92a8f3c --- /dev/null +++ b/debug-attachment.php @@ -0,0 +1,61 @@ +make(Illuminate\Contracts\Console\Kernel::class); +$kernel->bootstrap(); + +// ID from your error message +$id = '019b8920-93ee-7052-9282-b6f6b320b741'; + +echo "--- Attachment Debugger ---\n"; +echo "Target ID: $id\n\n"; + +// 1. Check Database +echo "[1] Checking Database Record...\n"; +$attachment = TicketAttachment::find($id); + +if (!$attachment) { + echo "ERROR: Record not found in database.\n"; + exit(1); +} + +echo "Found Record!\n"; +echo "- ID: " . $attachment->id . "\n"; +echo "- File Name: " . $attachment->file_name . "\n"; +echo "- Stored Path: " . $attachment->file_path . "\n"; +echo "- Created At: " . $attachment->created_at . "\n"; + +// 2. Check Disk +$path = $attachment->file_path; +$disk = 'r2-private'; + +echo "\n[2] Checking R2 Private Storage...\n"; +echo "Disk: $disk\n"; +echo "Path: $path\n"; + +try { + if (filter_var($path, FILTER_VALIDATE_URL)) { + echo "WARNING: Path is a full URL ($path). This logic is legacy/public.\n"; + exit; + } + + $exists = Storage::disk($disk)->exists($path); + + if ($exists) { + echo "STATUS: FILE EXISTS ✅\n"; + + // Try reading first 100 bytes + $content = Storage::disk($disk)->get($path); + echo "Read Test: Success (" . strlen($content) . " bytes read)\n"; + } else { + echo "STATUS: FILE NOT FOUND ❌\n"; + echo "Diagnosis: Upload failed or path mismatch.\n"; + } + +} catch (\Exception $e) { + echo "EXCEPTION: " . $e->getMessage() . "\n"; +}