I have a feeling that your problem is because if you are trying to display the jpeg in an html doc, then the wrong header is being supplied (text/html);
try using an external function that is kept on another page and in your function use header("Content-type: image/jpg");
before you try and print the binary data. This way you are actually grabbing the image from an external file with the correct header information.