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 Hi/Hj through ligation of their phosphate residues to the vacant Zr4+-ions associated with the NMOFs. The hairpins are engineered to include the miRNA recognition sequence in the stem domain of Hi, and in the Hi and Hj, 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 Hi, and this triggers the autonomous cross-opening of Hi and Hj. 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.