'jpg', 'image/png' => 'png', 'image/gif' => 'gif', 'image/webp' => 'webp', ]; public function store(UploadedFile $file): array { if (! $file->isValid()) { return [ 'ok' => false, 'status' => 400, 'error' => 'Invalid upload', ]; } $mime = strtolower((string) $file->getMimeType()); if (! isset($this->allowedTypes[$mime])) { return [ 'ok' => false, 'status' => 415, 'error' => 'Unsupported image type', ]; } if ($file->getSize() > self::MAX_SIZE_BYTES) { return [ 'ok' => false, 'status' => 413, 'error' => 'Image too large (max 5MB)', ]; } $targetDir = public_path('uploads/email'); if (! is_dir($targetDir)) { @mkdir($targetDir, 0755, true); } $ext = $this->allowedTypes[$mime]; $newName = 'em_'.bin2hex(random_bytes(16)).'.'.$ext; $file->move($targetDir, $newName); return [ 'ok' => true, 'url' => asset('uploads/email/'.$newName), ]; } }