Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.php > #19128

Re: Downloading strangeness: downloaded file has no content

From Tim Streater <timstreater@greenbee.net>
Newsgroups comp.lang.php
Subject Re: Downloading strangeness: downloaded file has no content
Date 2022-10-02 16:01 +0000
Message-ID <jptqveF5fg7U1@mid.individual.net> (permalink)
References <jpr2e0Fn0j4U1@mid.individual.net> <th9rhn$1chii$1@jstuckle.eternal-september.org> <jprjt4FpjjpU1@mid.individual.net> <thahjr$1egn0$1@jstuckle.eternal-september.org>

Show all headers | View raw


On 02 Oct 2022 at 00:13:55 BST, Jerry Stuckle <stuckle.jerry@gmail.com> wrote:

> On 10/1/2022 3:48 PM, Tim Streater wrote:
>> On 01 Oct 2022 at 17:57:19 BST, Jerry Stuckle <stuckle.jerry@gmail.com> 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:
>>>> 
>>>> <font color="#000000">header('Content-Description: File Transfer');</font>
>>>> 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. :-)
> 
> 131Mbytes?  That brings up another question.  Is this the largest of the
> files?  Does your hosting company have a file size limit?

That is the largest of the files, and following Aho's suggestion about
buffering seems to have fixed it, at least for using Safari under macOS to
download. I'll now fire up my VMs to check under Win/Lin. Permissions were OK.

Thanks for your help and suggestions. I've not used PHP for some years and had
forgotten what-all I used to do for testing this setup.

-- 
Tim

Back to comp.lang.php | Previous | NextPrevious in thread | Find similar


Thread

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