I think I see where you're going...
You're trying to log in a database any views of an image. But as you're noticing, the image isn't being displayed properly.
What you'll need to do is persuade PHP to read the contents of the desired image and feed it back to the browser.
Something like:
header('Content-type: image/jpeg');
readfile($NameOfDesiredImage);
Untested, but I think that will work. You'll need to remember change the content type based on the format of the image.