By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Problem using fpassthru()

P: n/a
I'm just learning PHP, and I'm having a problem using fpassthru(). I
want to download a file using the following code segment I found,
which I put into my testing file called portal.php:

$fileString = './' . $params[1];
// translate file name properly for Internet Explorer.
if ( strstr( $_SERVER['HTTP_USER_AGENT'], "MSIE" )) {
$params[1] = preg_replace( '/\./', '%2e', $params[1],
substr_count($params[1], '.') - 1 );
}
header( "Cache-Control: " ); // leave blank for IE
header( "Pragma: " ); // leave blank for IE
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=\"" .
$params[1] . "\"" );
header( "Content-length:" . (string)(filesize( $fileString )));
sleep(1);
$fdl = @fopen( $fileString, 'rb' );
fpassthru( $fdl );

However, when I run it, I get the following:

Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 178

Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 179

Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 180

Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 182

Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 183

The contents of the file I am trying to download (an html file) is
then displayed, interpreted as if it were appended to the end of
portal.php. Does anyone know what is causing this, and how I can fix
it? Thanks in advance to all who respond.
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 178

Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 179

Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 180

Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 182

Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 183


these are ussually caused when you have already output data to the browser,
if any output has been sent (even a single space) then headers can not be
sent
Jul 17 '05 #2

P: n/a
"Filth" <pe***@petermcdonald.co.uk> wrote in message news:<yn*******************@news-text.cableinet.net>...

these are usually caused when you have already output data to the browser,
if any output has been sent (even a single space) then headers can not be
sent


Thanks for your response. Now, am I using the wrong technique to download
a file from a host server? Is there a better way, or am I just using the
correct technique incorrectly? I would appreciate some guidance, since
PHP in general is still new to me.
Jul 17 '05 #3

P: n/a
Leslie Houk wrote:
Does anyone know what is causing this, and how I can fix
it? Thanks in advance to all who respond.


You need to use output buffering. Check the manual at
http://www.php.net/ob_start for somewhere to start.

Regards,

Andy
Jul 17 '05 #4

P: n/a
Andy Barfield <ab**********@yahoo.com> wrote in message news:<k6********************@nildram.net>...
Leslie Houk wrote:
Does anyone know what is causing this, and how I can fix
it? Thanks in advance to all who respond.


You need to use output buffering. Check the manual at
http://www.php.net/ob_start for somewhere to start.

Regards,

Andy


Andy,

Thanks for the link! The last user comment on that page pointed
me to "http://www.devshed.com/c/a/PHP/Output-Buffering-With-PHP/",
which told me exactly how to do what I need.

Leslie
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.