Elgg installation Mac OSX server

Hi,
I have just completed two Elgg installation on two locations, a Ubuntu server (Linux) and one on a MacOSX server. In the latter everything worked fine but for some strange reason in the latter, no images whether they were profile icons, images uploaded as files or embedded into pages would not show up or download correctly (in proper format). Download of the images worked but the file was invaribaly a corrupt jpg or png.
After tearing my hair off for almost the better part of a week, I finally found the solution: the images had uploaded alright to the [path_to_docroot]/data/files/[u/s/e/r/n/username/]images/[file name].[extension] as they are supposed to, and all images including the original and thumbnails generated properly. Finally I hit on a solution after noticing that the files would not open in any image viewer but an error message that informed me that the correct header for the image binary was WAS incorrect.
Turns out the php script method that displays image or streams it down as a download was somehow acting up only for MacOSX server (even though GD was included). I opened the image files in HEx viewer and sure enough the headers had some junk charaters had been prepended to the images displayed or made  downloaded by streaming through PHP image functions. I wrote basic image copying and streaming scripts which worked for me on the same OSX server anyway. However, since I am still studying the intricacies of Elgg classes and methods, I was unable to trace why the same methods did a perfectly okay job for in a Linux server bit not for my Release - 1.5, Version - 2009031301 Elgg installed on OSX. Although I am still a bit foxed about what the real problem is, I found a solution which makes things work like a charm.
Basically after sending appropriate image headers, just add two lines of PHP code, et voila, the image will display as it should and naturally also the download stream.
They are:
ob_clean();
flush();
This should appear in file(s) like /elgg/mod/file/thumbnail.php on  39 (verion 1.5, Version - 2009031301):
// Grab the file
if ($thumbfile && !empty($thumbfile)) {
        $readfile = new ElggFile();
        $readfile->owner_guid = $file->owner_guid;
        $readfile->setFilename($thumbfile);
        $mime = $file->getMimeType();
        header("Content-type: " . $mime); 
/*
ob_clean and flush added by Shubho, Date: 26-Oct-2009
Notes: After agonising over thumbnails, icons and downloads not working for images for over a week with same functional code as in Linux server, just a output buffer cleaning solves the problem. It's possible somewhere the server running on Mac OSX is adding some junk binary characters in the output buffer at some point owing to something in the Elgg lib code... at this point the issue remains a mystery. However a ob_clean cleans it up and it works well! Phew...
*/
        $contents = $readfile->grabFile();
        ob_clean();
        flush();
        echo $contents;
        exit;
    }
 
I hope this might help somone in the future... I wonder if the method $contents = $readfile->grabFile()'s code might have been written ignoring a possible buggy outcome.Can anyone help?