FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Return False on download
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Return False on download [message #170548] Sun, 07 November 2010 17:17 Go to next message
Brian Smither is currently offline  Brian Smither
Messages: 5
Registered: October 2010
Karma: 0
Junior Member
For the following code, can I get an opinion on what exactly the browser
will "do" or "receive" when the function returns false?


header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($val));
$filename = explode("/",$val);
$parts = count($filename);
header("Content-Disposition: attachment; filename=".$filename[$parts-1]);

function readfile_chunked($filename) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$handle = fopen($filename, 'rb');
if($handle === false) { return false; }
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
print $buffer;
}
return fclose($handle);
}

readfile_chunked($val);
exit;
Re: Return False on download [message #170550 is a reply to message #170548] Sun, 07 November 2010 19:23 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 11/7/2010 12:17 PM, Brian Smither wrote:
> For the following code, can I get an opinion on what exactly the browser
> will "do" or "receive" when the function returns false?
>
>
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Content-Type: application/octet-stream");
> header("Content-Length: " . filesize($val));
> $filename = explode("/",$val);
> $parts = count($filename);
> header("Content-Disposition: attachment; filename=".$filename[$parts-1]);
>
> function readfile_chunked($filename) {
> $chunksize = 1*(1024*1024); // how many bytes per chunk
> $buffer = '';
> $handle = fopen($filename, 'rb');
> if($handle === false) { return false; }
> while (!feof($handle)) {
> $buffer = fread($handle, $chunksize);
> print $buffer;
> }
> return fclose($handle);
> }
>
> readfile_chunked($val);
> exit;
>
>

Exactly what you sent - the headers and nothing else.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: checkbox own set and reload page
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 14 11:14:25 GMT 2024

Total time taken to generate the page: 0.02280 seconds