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.
Any suggestions as to why this might be?
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?
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.
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?
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. :-)
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.
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.
ob_clean ();
readfile ($file);
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 ownershipThis is worth checking too, no doubt about it. :-)
and permissions on the file? Does the web server have read access to it? >>
131Mbytes? That brings up another question. Is this the largest of the files? Does your hosting company have a file size limit?
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 readfile return?
Also do you get an exception?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 349 |
Nodes: | 16 (2 / 14) |
Uptime: | 120:32:49 |
Calls: | 7,612 |
Files: | 12,789 |
Messages: | 5,684,164 |