Re: Serving a .dmg via readfile?

From: Date: Thu, 26 Apr 2012 04:07:51 +0000
Subject: Re: Serving a .dmg via readfile?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-317687@lists.php.net to get a copy of this message
On 4/25/12 10:54 PM, Brian Dunning wrote:
Hey all - 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.
Most likely your file is larger than the memory you have available to PHP. The readfile() command will load the whole file into memory before streaming it out. You'll want to use fopen, fread, fwrite, and fclose to loop through bytes in your file as you shuttle chunks to the client instead of slooping it all into memory in one hunk. -- Dante D. Dante Lorenso dante@lorenso.com

« previous php.general (#317687) next »