An analytical platform for the selective miRNA-21-guided imaging of breast cancer cells and miRNA-221-guided imaging of ovarian cancer cells and the selective photodynamic therapy (PDT) of these cancer cells is introduced. The method is based on Zn(II)-protoporphyrin IX, Zn(II)-PPIX-loaded UiO-66 metal–organic framework nanoparticles, NMOFs, gated by two hairpins H i/H j through ligation of their phosphate residues to the vacant Zr 4+-ions associated with the NMOFs. The hairpins are engineered to include the miRNA recognition sequence in the stem domain of H i, and in the H i and H j, partial locked stem regions of G-quadruplex subunits. Intracellular phosphate-ions displace the hairpins, resulting in the release of the Zn(II)-PPIX and intracellular miRNAs open H i, and this triggers the autonomous cross-opening of H i and H j. This activates the interhairpin hybridization chain reaction and leads to the assembly of highly fluorescent Zn(II)-PPIX-loaded G-quadruplex chains. The miRNA-guided fluorescent chains allow selective imaging of cancer cells. Moreover, PDT with visible light selectively kills cancer cells and tumor cells through the formation of toxic reactive oxygen species.