This study proposes a flexible and stretchable 3D polymer film with photonic crystals for the visible detection of spoiled milk. Thermoplastic polyurethane (TPU) was used as the substrate for the photonic crystal structure. The back barrier layer with a regular array of nanohemispheres of anodic aluminum oxide film was used as a template for electroforming a nickel mold. The nanohemisphere array was then nanoimprinted onto the TPU substrate to form a strain-controllable photonic crystal (SCPC) structure on it. Food spoilage can be easily detected by the structural color change caused by the gas it produces. Experimental results confirmed that the structural color change of the fabricated SCPC TPU film occurred when the elongation (ΔL) of the film reached 0.2mm (1.2%). Furthermore, spoiled milk detection experiments showed that the proposed SCPC TPU film is a highly intelligent and cost-effective biosensor for detecting spoiled food in a container.