Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Due to lack of disk space, this fortune database has been discontinued.


devel / comp.lang.php / Re: Downloading strangeness: downloaded file has no content

SubjectAuthor
* Downloading strangeness: downloaded file has no contentTim Streater
+* Re: Downloading strangeness: downloaded file has no contentJ.O. Aho
|`* Re: Downloading strangeness: downloaded file has no contentTim Streater
| +- Re: Downloading strangeness: downloaded file has no contentJ.O. Aho
| `* Re: Downloading strangeness: downloaded file has no contentJ.O. Aho
|  `- Re: Downloading strangeness: downloaded file has no contentTim Streater
`* Re: Downloading strangeness: downloaded file has no contentJerry Stuckle
 `* Re: Downloading strangeness: downloaded file has no contentTim Streater
  `* Re: Downloading strangeness: downloaded file has no contentJerry Stuckle
   `- Re: Downloading strangeness: downloaded file has no contentTim Streater

1
Downloading strangeness: downloaded file has no content

<jpr2e0Fn0j4U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=690&group=comp.lang.php#690

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: timstreater@greenbee.net (Tim Streater)
Newsgroups: comp.lang.php
Subject: Downloading strangeness: downloaded file has no content
Date: 1 Oct 2022 14:50:40 GMT
Lines: 28
Message-ID: <jpr2e0Fn0j4U1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=fixed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net QYFwHqg/zfQJwkL+EDU10g4H8K99lN8X8Lt6e76WA+wN7hdR52
Cancel-Lock: sha1:tazLAnYjsGhysYI2IRf+P3k442s=
X-No-Archive: Yes
User-Agent: Usenapp for MacOS
X-Usenapp: v1.23/l - Full License
 by: Tim Streater - Sat, 1 Oct 2022 14:50 UTC

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?

--
HAL 9000: Dave. Put down those Windows disks. Dave. DAVE!

Re: Downloading strangeness: downloaded file has no content

<jpr993Fl2gbU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=691&group=comp.lang.php#691

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (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: <jpr993Fl2gbU1@mid.individual.net>
References: <jpr2e0Fn0j4U1@mid.individual.net>
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: <jpr2e0Fn0j4U1@mid.individual.net>
 by: J.O. Aho - Sat, 1 Oct 2022 16:47 UTC

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:
>
> <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.

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

Re: Downloading strangeness: downloaded file has no content

<th9rhn$1chii$1@jstuckle.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=692&group=comp.lang.php#692

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader01.eternal-september.org!jstuckle.eternal-september.org!.POSTED!not-for-mail
From: stuckle.jerry@gmail.com (Jerry Stuckle)
Newsgroups: comp.lang.php
Subject: Re: Downloading strangeness: downloaded file has no content
Date: Sat, 1 Oct 2022 12:57:19 -0400
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <th9rhn$1chii$1@jstuckle.eternal-september.org>
References: <jpr2e0Fn0j4U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 1 Oct 2022 16:57:27 -0000 (UTC)
Injection-Info: jstuckle.eternal-september.org; posting-host="264d4252f3e790594f87c756860c9158";
logging-data="1459794"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1ksdNREancnqufuboriaeit9PzplEPtI="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.1
Cancel-Lock: sha1:e2g6wjXdEXC4h1BCLFcCodRJcRA=
In-Reply-To: <jpr2e0Fn0j4U1@mid.individual.net>
Content-Language: en-US
 by: Jerry Stuckle - Sat, 1 Oct 2022 16:57 UTC

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.

Have you checked the contents of $file? Is it correct - including the
path? What is the result of filesize($file)? What are the ownership
and permissions on the file? Does the web server have read access to it?

--
==================
Remove the "x"'s from my email address
Jerry Stuckle
stucklex.jerryx@gmail.com
==================

Re: Downloading strangeness: downloaded file has no content

<jprjkeFpihiU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=693&group=comp.lang.php#693

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: timstreater@greenbee.net (Tim Streater)
Newsgroups: comp.lang.php
Subject: Re: Downloading strangeness: downloaded file has no content
Date: 1 Oct 2022 19:44:14 GMT
Lines: 49
Message-ID: <jprjkeFpihiU1@mid.individual.net>
References: <jpr2e0Fn0j4U1@mid.individual.net> <jpr993Fl2gbU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=fixed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net WHzUPEUwQze7EhrY3dM2OwUOh3Gvg1GAsHFE2bARz19TayTHye
Cancel-Lock: sha1:d85pGOAk5CUFWaU9M+4yB3qIEY4=
X-No-Archive: Yes
User-Agent: Usenapp for MacOS
X-Usenapp: v1.23/l - Full License
 by: Tim Streater - Sat, 1 Oct 2022 19:44 UTC

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

Re: Downloading strangeness: downloaded file has no content

<jprjt4FpjjpU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=694&group=comp.lang.php#694

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: timstreater@greenbee.net (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: <jprjt4FpjjpU1@mid.individual.net>
References: <jpr2e0Fn0j4U1@mid.individual.net> <th9rhn$1chii$1@jstuckle.eternal-september.org>
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
 by: Tim Streater - Sat, 1 Oct 2022 19:48 UTC

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. :-)

--
"... 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

Re: Downloading strangeness: downloaded file has no content

<jprsllFl2gaU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=695&group=comp.lang.php#695

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: comp.lang.php
Subject: Re: Downloading strangeness: downloaded file has no content
Date: Sun, 2 Oct 2022 00:18:29 +0200
Lines: 65
Message-ID: <jprsllFl2gaU1@mid.individual.net>
References: <jpr2e0Fn0j4U1@mid.individual.net>
<jpr993Fl2gbU1@mid.individual.net> <jprjkeFpihiU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net BngcnI2SqHS93U24e0+jVQ33Vw4Y/FFnpDwUKgJZsZF1yGkM6i
Cancel-Lock: sha1:4+3vHG+X5/754/WAY0xnt2BldHU=
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: <jprjkeFpihiU1@mid.individual.net>
 by: J.O. Aho - Sat, 1 Oct 2022 22:18 UTC

On 01/10/2022 21.44, Tim Streater wrote:
> 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.

My bad, my brain just didn't want to see that line at all, as it had
font-tag around it in the original post.

>>> 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.

Jerry had some good points, I will extend one of his suggestions, the
file permission and ownership, don't forget to look at the directories
too, specially if you are running on Linux, so if one directory in the
path do not have the right privileges set for the web server, then it
will not be able to access anything in the subdirectories and files,
even if they would have the correct privileges.

Most likely in this case you need to look that either group rx on
directories and r on files, some web-hosting sadly have it even worse
and require other setting to have rx for directories and r for files.
You will need to compare with a file that works to download from the web
site with the one that do not work.

I hope that ftp you mention is actually an sftp, otherwise anyone who
can sniff the traffic will be able to get your password in plain text.

--

//Aho

Re: Downloading strangeness: downloaded file has no content

<thahjr$1egn0$1@jstuckle.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=696&group=comp.lang.php#696

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!jstuckle.eternal-september.org!.POSTED!not-for-mail
From: stuckle.jerry@gmail.com (Jerry Stuckle)
Newsgroups: comp.lang.php
Subject: Re: Downloading strangeness: downloaded file has no content
Date: Sat, 1 Oct 2022 19:13:55 -0400
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <thahjr$1egn0$1@jstuckle.eternal-september.org>
References: <jpr2e0Fn0j4U1@mid.individual.net>
<th9rhn$1chii$1@jstuckle.eternal-september.org>
<jprjt4FpjjpU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 1 Oct 2022 23:14:03 -0000 (UTC)
Injection-Info: jstuckle.eternal-september.org; posting-host="c29f48f37c573fee87560f85add6fdd3";
logging-data="1524448"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/8YLEoiFPiX+xk2It1OKqqtRPixptbs4="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.1
Cancel-Lock: sha1:lYapU6IxN0EjTzdP7z83gWa+3R8=
In-Reply-To: <jprjt4FpjjpU1@mid.individual.net>
Content-Language: en-US
 by: Jerry Stuckle - Sat, 1 Oct 2022 23:13 UTC

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. :-)
>

Tim,

131Mbytes? That brings up another question. Is this the larges of the
files? Does your hosting company have a file size limit?

Jerry

--
==================
Remove the "x"'s from my email address
Jerry Stuckle
stucklex.jerryx@gmail.com
==================

Re: Downloading strangeness: downloaded file has no content

<jpt6jlFl2gaU2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=697&group=comp.lang.php#697

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: comp.lang.php
Subject: Re: Downloading strangeness: downloaded file has no content
Date: Sun, 2 Oct 2022 12:14:13 +0200
Lines: 41
Message-ID: <jpt6jlFl2gaU2@mid.individual.net>
References: <jpr2e0Fn0j4U1@mid.individual.net>
<jpr993Fl2gbU1@mid.individual.net> <jprjkeFpihiU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 06pBNzTmOwoyUnH0eVX3gA/x9c0mzJp7sSVH94LNgdxbEIe++a
Cancel-Lock: sha1:2L1meklXQZn/Rr9WNodWqcNlEWM=
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: <jprjkeFpihiU1@mid.individual.net>
 by: J.O. Aho - Sun, 2 Oct 2022 10:14 UTC

On 01/10/2022 21.44, Tim Streater wrote:

>>> ob_clean ();

This will just clean out the output buffer, so the max size would then
be limited of the buffer size, think you need to switch to use
ob_end_clean() which disables the output buffer and is recommended in
the php documentation for readfile.

>>> readfile ($file);

By the way, what value does the redfile return?
Also do you get an exception?
Could also be got to check the file exists and can be read

If(file_exists($file)) is_file($file))
{ if(is_file($file)) {
if(is_readable($file)) {
try {
$retval = readfile ($file);
// log the retval to your logfile
} catch (Exception $ex) {
//log the exception here
}
} else {
// log that file not readable
}
} else {
// log file not really a file, most likely a directory
}
} else {
// log the file do not exists
}

--

//Aho

Re: Downloading strangeness: downloaded file has no content

<jptqn5F5ec9U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=698&group=comp.lang.php#698

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: timstreater@greenbee.net (Tim Streater)
Newsgroups: comp.lang.php
Subject: Re: Downloading strangeness: downloaded file has no content
Date: 2 Oct 2022 15:57:25 GMT
Lines: 26
Message-ID: <jptqn5F5ec9U1@mid.individual.net>
References: <jpr2e0Fn0j4U1@mid.individual.net> <jpr993Fl2gbU1@mid.individual.net> <jprjkeFpihiU1@mid.individual.net> <jpt6jlFl2gaU2@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=fixed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net jnIf3gr08QGJr3dYrEloUwhiRGqIT6t+h6/3je/8iBYOXrv1IB
Cancel-Lock: sha1:U3w6GSd+5gcCxzwIRqZwpBoEmYU=
X-No-Archive: Yes
User-Agent: Usenapp for MacOS
X-Usenapp: v1.23/l - Full License
 by: Tim Streater - Sun, 2 Oct 2022 15:57 UTC

On 02 Oct 2022 at 11:14:13 BST, "J.O. Aho" <user@example.net> wrote:

> On 01/10/2022 21.44, Tim Streater wrote:
>
>>>> ob_clean ();
>
> This will just clean out the output buffer, so the max size would then
> be limited of the buffer size, think you need to switch to use
> ob_end_clean() which disables the output buffer and is recommended in
> the php documentation for readfile.

This solved the problem.

>>>> readfile ($file);
>
> By the way, what value does the readfile return?
> Also do you get an exception?

I think I must have got a real error or exception at this point, as code after
the readfile to check the readfile return and also compare with filesize() was
not executed. I've not heard back from the hosting provider at this point.

Thanks for your help.

--
"The idea that Bill Gates has appeared like a knight in shining armour to lead all customers out of a mire of technological chaos neatly ignores the fact that it was he who, by peddling second-rate technology, led them into it in the first place." - Douglas Adams

Re: Downloading strangeness: downloaded file has no content

<jptqveF5fg7U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=699&group=comp.lang.php#699

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: timstreater@greenbee.net (Tim Streater)
Newsgroups: comp.lang.php
Subject: Re: Downloading strangeness: downloaded file has no content
Date: 2 Oct 2022 16:01:51 GMT
Lines: 64
Message-ID: <jptqveF5fg7U1@mid.individual.net>
References: <jpr2e0Fn0j4U1@mid.individual.net> <th9rhn$1chii$1@jstuckle.eternal-september.org> <jprjt4FpjjpU1@mid.individual.net> <thahjr$1egn0$1@jstuckle.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=fixed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net wSHDAj8zzN7eYDpD+iX6fwbE5AvzQoqGawLx/w16NkoDx77SCi
Cancel-Lock: sha1:VpSArxc0/pBE6tEkFeM1pj5Of78=
X-No-Archive: Yes
User-Agent: Usenapp for MacOS
X-Usenapp: v1.23/l - Full License
 by: Tim Streater - Sun, 2 Oct 2022 16:01 UTC

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

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor