On 31-01-2012 15:34, Michael Shestero wrote:


header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=f.bzip2");
header("Content-Type: application/x-bzip2");
//header("Content-length: " . strlen($zippedfile) . "\n\n");
header("Content-Transfer-Encoding: binary");
ob_flush();

$bz = bzopen( 'php://output' , 'w' ); if ($bz===FALSE) { echo "FALSE";
return; }
bzwrite($bz,"hi");
bzclose($bz);

bzopen returns error:
bzopen(): cannot represent a stream of type Output as a File Descriptor

in case using stdout instead of output it works but produce zero result.

Following works ok:

$z = fopen( 'php://output' , 'w' );
if ($z===FALSE) { echo "FALSE"; return; }
fwrite($z,"hihi");
fclose($z);

Please, help!



What exactly are you trying to do? From the top section it seems like you're trying to output back via the standard output channel, meaning as the body of a response. This assumes you're working in a client/server relationship, where PHP is invoked server-side as a script, and its response is being sent back to the client (browser).

But then all of a sudden, you start opening php://output which is an output stream which exists solely in the cli-mode!

So, your answer is simply:
1. in the case of a browser/server type of relation:
<?php
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=f.txt.bz2");
header("Content-Type: application/x-bzip2");
header("Content-Transfer-Encoding: binary");

$compressed_string = bzcompress("hi");

echo $compressed_string;

2. In the case that you're using php-cli, get rid of all the header stuff. It's useless here.

- Tul

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to