How to serve a .dmg file via PHP/readfile?

dmg, http-headers, php, readfile

Solution

Found the solution. The culprit was readfile() and may have been memory related. In place of the readfile() line, I'm using this:

$fd = fopen ('/var/www/mypath/My Cool Image.dmg', "r");
while(!feof($fd)) {
    set_time_limit(30);
    echo fread($fd, 4096);
    flush();
}
fclose ($fd);

It's now serving all filetypes properly, DMG included.

Problem

I'm having no luck serving a .dmg from my online store. I stripped down the code to just the following to debug, but no matter what I get a zero-byte file served: ``` header('Content-Type: application/x-apple-diskimage'); // also tried octet-stream header('Content-Disposition: attachment; filename="My Cool Image.dmg"'); $size = filesize('/var/www/mypath/My Cool Image.dmg'); header('Content-Length: '.$size); readfile('/var/www/mypath/My Cool Image.dmg'); ``` This same code works for a number of other file types that I serve: bin, zip, pdf. Any suggestions? Professor Google is not my friend.

Original source