Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Tim Streater Newsgroups: comp.lang.php Subject: Re: Downloading strangeness: downloaded file has no content Date: 1 Oct 2022 19:48:52 GMT Lines: 52 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=fixed Content-Transfer-Encoding: 8bit X-Trace: individual.net ADCunNtzGSZ95S5rR1P57wmdr7Mnvc8WBUWPHejjTL4Yu9gl/c Cancel-Lock: sha1:stoyEi3dItP4krndniaz/jNKrio= X-No-Archive: Yes User-Agent: Usenapp for MacOS X-Usenapp: v1.23/l - Full License Xref: csiph.com comp.lang.php:19123 On 01 Oct 2022 at 17:57:19 BST, Jerry Stuckle wrote: > On 10/1/2022 10:50 AM, 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. The file on the server is correct - I can download it using an FTP >> client and drag/drop the file off the server and onto my desktop. Then it has >> the correct size/content. >> >> Any suggestions as to why this might be? > > Tim, > > What's in your PHP error log? It's always the first place I check when > I have weird problems. Good question. I'll have to get on to the hosting provider or see whether with the tools I have access to, I can locate it. I was minded to contact them anyway, in case there's some file caching issue that requires a restart of whatever VM they're running for me. > Have you checked the contents of $file? Is it correct - including the > path? What is the result of filesize($file)? I log these items just before the first header is sent and they are as expected. Filesize is 131Mbytes (not easily overlooked). > What are the ownership > and permissions on the file? Does the web server have read access to it? This is worth checking too, no doubt about it. :-) -- "... you must remember that if you're trying to propagate a creed of poverty, gentleness and tolerance, you need a very rich, powerful, authoritarian organisation to do it." - Vice-Pope Eric