Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: Downloading strangeness: downloaded file has no content Date: Sat, 1 Oct 2022 18:47:31 +0200 Lines: 40 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net CUQTnqQhuIHIvLgDyDEkbANTrKSUquZuyrU/jJqK2idpGy6811 Cancel-Lock: sha1:fKon9dDe/mDp6fsp7RR2C3eKUcc= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Content-Language: en-US-large In-Reply-To: Xref: csiph.com comp.lang.php:19120 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'); 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. > 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. -- //Aho