A pediatrician who owns a medical practice in Montgomery County was busted on child pornography charges after his own nurse discovered his massive collection, prosecutors said.

Dr. David S. Kennedy, 48, of Pennsburg, admitted to possessing the images after a nurse found them on an iPhone he had bought for her and reported him to authorities, the Montgomery County DA’s office announced Wednesday.

Kennedy’s collection came to light over the Thanksgiving holiday.

Prosecutors said he bought an iPhone7 Plus for a nurse at Personal Care Pediatrics in Pennsburg, which he owned, after she volunteered to handle after-hours calls over Thanksgiving weekend.

He bought the phone Nov. 22 and gave it to the nurse on Nov. 23, but didn’t realize when he synced it to his account that it would connect to his massive cache of pornography, including child porn, prosecutors said.

“Dr. David Kennedy believed it was only the address book shared. He was unaware his photo stream, contained in the iCloud, was also connected to the new iPhone7 Plus,” the criminal complaint states.

Over the holidays, the nurse used the phone while she was in possession of it to answer calls from patients, look up medical information for patients, and take pictures of her Thanksgiving gathering.

But when she went into the “Photo Album” folder on the phone, “she found what she estimated to be hundreds of digital images of naked women,” according to the criminal complaint. The nurse “thought that some of the images might depict females under the age of 18.”

Later, while using the phone to review a medical chart for children’s medication, she allegedly found a label in the web browser called “David’s iCloud,” with suggested sites that had graphic titles referring to child pornography.

On Nov. 28, the nurse contacted authorities. Dr. Kennedy later admitted to authorities that he had downloaded images of child porn, prosecutors said. Police also searched two iPhone 5s he had in his possession, which reportedly contained more child porn and websites with child pornography in the web browser histories.

Kennedy was arrested that day and charged with sexual abuse of children and criminal use of a communications facility. He is being held in Montgomery County Correctional Facility after failing to make bail, prosecutors said.