RE: [PHP-WIN] "Headers already sent" error message
| From: | dash php | Date: | Thu, 22 Aug 2002 16:38:56 +0000 |
| Subject: | RE: [PHP-WIN] "Headers already sent" error message | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-15458@lists.php.net to get a copy of this message | ||
echo "$type, $filename";
You have this line before the header command.
That, uh, could be your problem.
-Dash
-----Original Message-----
From: R.S. Herhuth [mailto:ronherhuth@pop.mindspring.com]
Sent: Thursday, August 22, 2002 9:41 AM
To: Richard Black
Cc: ronherhuth@mindspring.com; php-windows@lists.php.net
Subject: Re: [PHP-WIN] "Headers already sent" error message
Here is the code for the page:
<?
// BEGIN FUNCTIONS -------------------------------------------
// message types
$type = array("text", "multipart", "message", "application",
"audio",
"image", "video", "other");
// message encodings
$encoding = array("7bit", "8bit", "binary", "base64",
"quoted-printable", "other");
// parse message body
function read($structure)
{
global $type;
global $encoding;
// create an array to hold message sections
$ret = array();
// split structure into parts
$parts = $structure->parts;
/*
iterate through parts
and create an array whose every element
represents one part
each element is itself an associative array
with keys representing the
- part number
- part type
- encoding
- disposition
- size
- filename
*/
for($x=0; $x<sizeof($parts); $x++)
{
$ret[$x]["pid"] = ($x+1);
$this = $parts[$x];
if ($this->type == "") { $this->type = 0; }
$ret[$x]["type"] = $type[$this->type] . "/" .
strtolower($this->subtype);
// default to 7bit
if ($this->encoding == "") { $this->encoding = 0; }
$ret[$x]["encoding"] = $encoding[$this->encoding];
if(isset($this->bytes))
{
$ret[$x]["size"] = strtolower($this->bytes);
}
if(isset($this->disposition))
{
$ret[$x]["disposition"] =
strtolower($this->disposition);
if (strtolower($this->disposition) ==
"attachment")
{
$params = $this->dparameters;
foreach ($params as $p)
{
if($p->attribute == "filename")
{
$ret[$x]["name"] = $p->value;
break;
}
}
}
}else
{
$ret[$x]["disposition"] = "NULL";
}
}
return $ret;
}
// iterate through object returned by parse()
// create a new array holding information only on message attachments
function get_attachments($arr)
{
for($x=0; $x<sizeof($arr); $x++)
{
if($arr[$x]["disposition"] == "attachment")
{
$ret[] = $arr[$x];
}
}
return $ret;
}
// END FUNCTIONS
------------------------------------------------------------------
$title = "Download Attachment";
$id=$_GET['id'];
$pid=$_GET['pid'];
$mailserver="mail.myurl.com";
$username="user";
$password="pass";
$inbox = imap_open("{" . $mailserver
."/imap}INBOX",$username,$password);
// parse message structure
$structure = imap_fetchstructure($inbox, $id);
$sections = read($structure);
// look for specified part
for($x=0; $x<sizeof($sections); $x++)
{
if($sections[$x]["pid"] == $pid)
{
$type = $sections[$x]["type"];
$encoding = $sections[$x]["encoding"];
$filename = $sections[$x]["name"];
}
}
$attachment = imap_fetchbody($inbox, $id, $pid);
// send headers to browser to initiate file download
echo "$type, $filename";
header ("Content-Type: $type; Content-Disposition: attachment;
filename=$filename" );
if ($encoding == "base64")
{
// decode and send
echo imap_base64($attachment);
}
else
{
// add handlers for other encodings here
echo $attachment;
}
// clean up
imap_close($inbox);
?>
Richard Black wrote:
>
> Any output before the header() call will cause this message.
>
> I would guess that the logic checks are outputting something?
>
> HTH,
>
> Richy
>
> ==========================================
> Richard Black
> Systems Programmer, DataVisibility Ltd -
> http://www.datavisibility.com
> Tel: 0141 435 3504
> Email: rblack@datavisibility.co.uk
>
> -----Original Message-----
> From: R.S. Herhuth [mailto:ronherhuth@pop.mindspring.com]
> Sent: 22 August 2002 17:15
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] "Headers already sent" error message
>
> I'm having a bit of trouble understanding why I'm getting a "Cannot add
> header information; Headers already sent" error message. I have several
> pages where I'm using the headers with no problems...but this single
> page I keep getting the error. The only real difference is that this
> page has a bunch of logic checks before it calls the header command.
>
> What is the cause of this error? what sort of things should I check
> for?
>
> I'm lost,
> Ron
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php