Hello smart and friendly MODx folks... I could post this in some other site, but I thought I’d try my favorite peeps first...
I built a page that checks whether a member is logged in with the correct permissions (no problem), then it streams a zip file from outside the document root using a script something like this:
http://www.domain.com/downloader.php?file=somefile.zip
This ensures that only logged-in members can download the assets (for legal reasons). In development, this worked fine, but now all of a sudden, we’re experiencing strange problems:
The guts of this essentially center around the following PHP lines:
$fullfilename = '/full/path/to/file.zip';
$f = 'filename_displayed_to_user.zip';
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$f");
readfile("$fullfilename");
The zip files download as expected -- that is the browser automatically downloads the file when the above code is run, but we can’t double click the zip files to open them. We know that the zip files are healthy and uncorrupted because when we put them somewhere in the document root (e.g.
http://www.domain.com/folder/somefile.zip), we can download the files without any problems. But when we access the files via the above URL (i.e. streaming the files via the above PHP code), the downloaded zip files do not immediately open. On a Mac, double-clicking the zip file causes it to create another file with a .cpgz extension.
What is this? Stuffit can’t open it... but Springy can (a 3rd party app). Nothing on the Windows side seems to be able read inside the files...
Springy allows us to extract everything "normally"... but what on earth is causing this? Some of the files are large (e.g. 80MB), but this problem is also occurring with our small test files (e.g. 10kb).
If anyone has any ideas, I’d love to hear them. I haven’t changed anything fundamentally in the code since this was tested successfully in development.