Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.lang.php > #19122
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Downloading strangeness: downloaded file has no content |
| Date | 2022-10-01 19:44 +0000 |
| Message-ID | <jprjkeFpihiU1@mid.individual.net> (permalink) |
| References | <jpr2e0Fn0j4U1@mid.individual.net> <jpr993Fl2gbU1@mid.individual.net> |
On 01 Oct 2022 at 17:47:31 BST, "J.O. Aho" <user@example.net> wrote:
> On 01/10/2022 16.50, Tim Streater wrote:
>> For those requesting that a file be downloaded from my website, having
>> selected a file (a .zip or a .dmg), the following is then executed:
>>
>> header('Content-Description: File Transfer');
>> header('Content-Type: application/octet-stream');
>> header('Content-Disposition: attachment; filename="' . basename ($file) . '"');
>> header('Content-Transfer-Encoding: binary');
>> header('Expires: 0');
>> header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
>> header('Pragma: public');
>> header('Content-Length: ' . filesize ($file));
>>
>> ob_clean ();
>> flush ();
>> readfile ($file);
>>
>>
>> For most of the files to be downloaded, this works just fine. But for one of
>> them, the downloaded file has zero content at the receiver's end: it is zero
>> bytes long.
>
> It could be a missing
> header('Content-Description: File Transfer');
That header is present. It's the first one.
> or it could be the html in the beginning of the page that causes the
> browser to think the file data is part of the web page.
In which case I'd expect none of the downloads to work, whereas they work for
4 out of the 5 files. This whole approach has worked without issue for several
years.
>> Any suggestions as to why this might be?
>
> If you are just doing what you paste here, I would suggest a direct link
> to the file instead.
The above code is the end of the chain during which the user makes their
choice and has it validated. Before the above code there is some parameter
checking and a bit of logging.
--
If socialism helps the poor, why are the poor in socialist countries so much poorer than the poor in capitalist countries?
Mark
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar
Downloading strangeness: downloaded file has no content Tim Streater <timstreater@greenbee.net> - 2022-10-01 14:50 +0000
Re: Downloading strangeness: downloaded file has no content "J.O. Aho" <user@example.net> - 2022-10-01 18:47 +0200
Re: Downloading strangeness: downloaded file has no content Tim Streater <timstreater@greenbee.net> - 2022-10-01 19:44 +0000
Re: Downloading strangeness: downloaded file has no content "J.O. Aho" <user@example.net> - 2022-10-02 00:18 +0200
Re: Downloading strangeness: downloaded file has no content "J.O. Aho" <user@example.net> - 2022-10-02 12:14 +0200
Re: Downloading strangeness: downloaded file has no content Tim Streater <timstreater@greenbee.net> - 2022-10-02 15:57 +0000
Re: Downloading strangeness: downloaded file has no content Jerry Stuckle <stuckle.jerry@gmail.com> - 2022-10-01 12:57 -0400
Re: Downloading strangeness: downloaded file has no content Tim Streater <timstreater@greenbee.net> - 2022-10-01 19:48 +0000
Re: Downloading strangeness: downloaded file has no content Jerry Stuckle <stuckle.jerry@gmail.com> - 2022-10-01 19:13 -0400
Re: Downloading strangeness: downloaded file has no content Tim Streater <timstreater@greenbee.net> - 2022-10-02 16:01 +0000
csiph-web