Most molecular clouds are filamentary or elongated. Among those forming low-mass stars, their long axes tend to be either parallel or perpendicular to the large-scale (10-100 pc) magnetic field (B-field) in the surrounding inter cloud medium. This arises because, along the dynamically dominant B-fields, the competition between self-gravity and turbulent pressure will shape the cloud to be elongated either perpendicular or parallel to the fields. Recent study also suggested that, on the scales of 0.1-0.01 pc, fields are dynamically important within cloud cores forming massive stars. But whether the core field morphologies are inherited from the inter cloud medium or governed by cloud turbulence is under vigorous debate, so is the role played by B-fields in cloud fragmentation at 10 - 0.1 pc scales. Here we report B-field maps covering 100-0.01 pc scales inferred from polarimetric observations of a massive-star forming region, NGC 6334. First, the main filament also lies perpendicular to the ambient field. NGC 6334 hosts young star-forming sites where fields are not severely affected by stellar feedback, and their directions do not change significantly over the entire scale range. This means that the fields are dynamically important. At various scales, we find that the hourglass-shaped field lines are pinched where the gas column density peaks and the field strength is proportional to the 0.4-power of the density. We conclude that B-fields play a crucial role in the fragmentation of NGC 6334.