When you press the shutter release button the shutter is lifted and light is allowed into the camera and hits the sensor. This is the way it worked in traditional camera's aswell but instead of a sensor the light would be projected onto film.
There are two types of sensors CCD (Charged coupled device) and CMOS (Complementary metal oxide semiconductor). Both sensors measure light and convert the analog signal into a digital signal which is then saved to the camera's SD card.
Advantages of CCD over CMOS:
CCD sensors create high-quality, low noise
images.
CCD sensors give greater sensitivity and
fidelity.
CCD have 100 times more power over CMOS sensors.
CCD require a specialized
assembly line to be made.
Advantages of CMOS over CCD:
CMOS sensors are more susceptible to
noise.
CMOS have a lower light sensitivity compared to CCD.
CMOS consume a lower amount of power compared to CCD.
CMOS sensors are easy to manufacture and are therefore cheaper to be made.
Below is an infographic showing how a picture is converted into a saved file. Source

Below is an example of an open shutter you can see the sensor on the right.