sanitizeFilename

Sanitizes a filename to prevent directory traversal attacks.

This function:

  1. Extracts the last segment of a path (the actual filename).

  2. Removes any remaining path separators (/ or \).

  3. Removes sequences that could be used for traversal (e.g., ..).

Return

The sanitized filename.