Alhazen (Ibn Al-Haytham), a great authority on optics in the Middle Ages who lived around 1000AD, invented the first pinhole camera, (also called the Camera Obscura} and was able to explain why the images were upside down.
By Mary Bellis, About.com Guide
History of PhotographyTimeline of Photography, Film, and CamerasThe Daguerreotype Process