This warrants a comment but is too long to fit:
It sounds like you want to compare the images and not the files themselves. The latter would be easy. I presume then you want to do the harder image comparison.
The problem with JPEG is that it is lossy. The process introduces errors. If you take a JPEG image, open it up and save it again, then open the saved image, it is likely not to be exactly the same as the first image.
Even if the sampling and quantization tables are the same, you can still get rounding errors.
First check if the pixel dimensions match. Then, for each pixel, convert to the YCbCr color space and compare the values within a range.
Pseudocode
srcY = YfromRGB (srcR, srcG, srcB) ;
dstY = YfromRGB (dstR, dstG, dstB) ;
if ((srcY - dstY) * (srcY - dstY) < SOMEDELTA) they are roughy the same
do the same for Cb and Cr for every pixel.
Here, I have only taken into account JPEG process difference. Some encoders may do gamma correction throwing the thing off even more.