cakephp tcpd错误:一些数据已经输出到浏览器,can';t在远程服务器上发送PDF文件
尝试从远程服务器查看\u of_holidays.pdf的列表时,我收到以下警告:cakephp tcpd错误:一些数据已经输出到浏览器,can';t在远程服务器上发送PDF文件,php,cakephp,tcpdf,Php,Cakephp,Tcpdf,尝试从远程服务器查看\u of_holidays.pdf的列表时,我收到以下警告: Warning (2): Cannot modify header information - headers already sent by (output started at /home/aquinto1/app/views/helpers/flash.php:155) [APP/vendors/tcpdf/tcpdf.php, line 8541] TCPDF ERROR: Some dat
Warning (2): Cannot modify header information - headers already sent by (output started
at /home/aquinto1/app/views/helpers/flash.php:155) [APP/vendors/tcpdf/tcpdf.php, line 8541]
TCPDF ERROR: Some data has already been output to browser, can't send PDF file
第155行是flash.php中的最后一行,即php的结束标记(?>)。在此之前,它是嵌入SWF的代码。我看不出有什么问题 但是,它在本地服务器上显示良好 我已经检查了空格,但错误仍然存在 在输出之前,我已经在使用ob_clean了 有人能告诉我我做错了什么吗。仅供参考,我正在使用cakephp和tcpdf 下面是flash.php
class FlashHelper extends AppHelper {
var $helpers = array('Javascript');
/**
* Used for remembering options from init() to each renderSwf
*
* @var array
*/
var $options = array(
'width' => 100,
'height' => 100
);
/**
* Used by renderSwf to set a flash version requirement
*
* @var string
*/
var $defaultVersionRequirement = '9.0.0';
/**
* Used by renderSwf to only call init if it hasnt been done, either
* manually or automatically by a former renderSwf()
*
* @var boolean
*/
var $initialized = false;
/**
* Optional initializing for setting default parameters and also includes the
* swf library. Should be called once, but if using several groups of flashes,
* MAY be called several times, once before each group.
*
* @example echo $flash->init();
* @example $flash->init(array('width'=>200,'height'=>100);
* @return mixed String if it was not able to add the script to the view, true if it was
*/
function init($options = array()) {
if (!empty($options)) {
$this->options = am($this->options, $options);
}
$this->initialized = true;
$view =& ClassRegistry::getObject('view');
if (is_object($view)) {
$view->addScript($this->Javascript->link('swfobject'));
return true;
} else {
return $this->Javascript->link('swfobject');
}
}
/**
* Wrapper for the SwfObject::embedSWF method in the vendor. This method will write a javascript code
* block that calls that javascript method. If given a dom id as fourth parameter the flash will
* replace that dom object. If false is given, a div will be placed at the point in the
* page that this method is echo'ed. The last parameter is mainly used for sending in extra settings to
* the embedding code, like parameters and attributes. It may also send in flashvars to the flash.
*
* For doucumentation on what options can be sent, look here:
* http://code.google.com/p/swfobject/wiki/documentation
*
* @example echo $flash->renderSwf('counter.swf'); // size set with init();
* @example echo $flash->renderSwf('flash/ad.swf',100,20);
* @example echo $flash->renderSwf('swf/banner.swf',800,200,'banner_ad',array('params'=>array('wmode'=>'opaque')));
* @param string $swfFile Filename (with paths relative to webroot)
* @param int $width if null, will use width set by FlashHelper::init()
* @param int $height if null, will use height set by FlashHelper::init()
* @param mixed $divDomId false or string : dom id
* @param array $options array('flashvars'=>array(),'params'=>array('wmode'=>'opaque'),'attributes'=>array());
* See SwfObject documentation for valid options
* @return string
*/
function renderSwf($swfFile, $width = null, $height = null, $divDomId = false, $options = array()) {
$options = am ($this->options, $options);
if (is_null($width)) {
$width = $options['width'];
}
if (is_null($height)) {
$height = $options['height'];
}
$ret = '';
if (!$this->initialized) {
$init = $this->init($options);
if (is_string($init)) {
$ret = $init;
}
$this->initialized = TRUE;
}
$flashvars = '{}';
$params = '{wmode : "opaque"}';
$attributes = '{}';
if (isset($options['flashvars'])) {
$flashvars = $this->Javascript->object($options['flashvars']);
}
if (isset($options['params'])) {
$params = $this->Javascript->object($options['params']);
}
if (isset($options['attributes'])) {
$attributes = $this->Javascript->object($options['attributes']);
}
if ($divDomId === false) {
$divDomId = uniqid('c_');
$ret .= '<div id="'.$divDomId.'"></div>';
}
if (isset($options['version'])) {
$version = $options['version'];
} else {
$version = $this->defaultVersionRequirement;
}
if (isset($options['install'])) {
$install = $options['install'];
} else {
$install = '';
}
$swfLocation = $this->webroot.$swfFile;
$ret .= $this->Javascript->codeBlock(
'swfobject.embedSWF
("'.$swfLocation.'", "'.$divDomId.'", "'.$width.'", "'.$height.'", "'.$version.'",
"'.$install.'", '.$flashvars.', '.$params.', '.$attributes.');');
return $ret;
}
}
?>
类FlashHelper扩展了AppHelper{
var$helpers=array('Javascript');
/**
*用于记住从init()到每个renderSwf的选项
*
*@var数组
*/
var$options=数组(
“宽度”=>100,
“高度”=>100
);
/**
*renderSwf用于设置flash版本要求
*
*@var字符串
*/
var$defaultVersionRequirement='9.0.0';
/**
*renderSwf用于仅在尚未调用init时调用init
*由以前的renderSwf()手动或自动执行
*
*@var布尔值
*/
var$initialized=false;
/**
*用于设置默认参数的可选初始化,还包括
*swf library.应调用一次,但如果使用多组闪光灯,
*可多次呼叫,每组前一次。
*
*@example echo$flash->init();
*@example$flash->init(数组('width'=>200,'height'=>100);
*@return mixed String,如果无法将脚本添加到视图中,则返回true
*/
函数init($options=array()){
如果(!empty($options)){
$this->options=am($this->options,$options);
}
$this->initialized=true;
$view=&ClassRegistry::getObject('view');
如果(是对象($view)){
$view->addScript($this->Javascript->link('swfobject');
返回true;
}否则{
返回$this->Javascript->link('swfobject');
}
}
/**
*供应商中SwfObject::embedSWF方法的包装器。此方法将编写javascript代码
*块调用该javascript方法。如果给定dom id作为第四个参数,flash将
*替换该dom对象。如果给定false,将在
*返回此方法的页面。最后一个参数主要用于向发送额外设置
*嵌入代码,如参数和属性。它还可以向flash发送FlashVar。
*
*有关可发送哪些选项的详细说明,请参见此处:
* http://code.google.com/p/swfobject/wiki/documentation
*
*@example echo$flash->renderSwf('counter.swf');//使用init()设置大小;
*@example echo$flash->renderSwf('flash/ad.swf',100,20);
*@example echo$flash->renderSwf('swf/banner.swf',800200,'banner_ad',array('params'=>array('wmode'=>'不透明'));
*@param string$swfFile文件名(具有相对于webroot的路径)
*@param int$width如果为null,将使用FlashHelper::init()设置的宽度
*@param int$height如果为null,将使用FlashHelper::init()设置的高度
*@param mixed$divDomId false或string:dom id
*@param array$options数组('flashvars'=>array(),'params'=>array('wmode'=>'不透明'),'attributes'=>array());
*有关有效选项,请参见SwfObject文档
*@返回字符串
*/
函数renderSwf($swfFile,$width=null,$height=null,$divDomId=false,$options=array()){
$options=am($this->options,$options);
如果(为空($width)){
$width=$options['width'];
}
如果(为空($height)){
$height=$options['height'];
}
$ret='';
如果(!$this->initialized){
$init=$this->init($options);
如果(是字符串($init)){
$ret=$init;
}
$this->initialized=TRUE;
}
$flashvars='{}';
$params='{wmode:“不透明”}';
$attributes='{}';
如果(isset($options['flashvars']){
$flashvars=$this->Javascript->object($options['flashvars']);
}
if(isset($options['params']){
$params=$this->Javascript->object($options['params']);
}
if(isset($options['attributes']){
$attributes=$this->Javascript->object($options['attributes']);
}
如果($divDomId==false){
$divDomId=uniqid('c_');
$ret.='';
}
如果(isset($options['version']){
$version=$options['version'];
}否则{
$version=$this->defaultVersionRequirement;
}
如果(isset($options['install']){
$install=$options['install'];
}否则{
$install='';
}
$swfLocation=$this->webroot.$swfFile;
$ret.=$this->Javascript->codeBlock(
'swfobject.embeddeswf
(“..swfLocation.”、“..divDomId.”、“..width.”、“..height.”、“..version.”,
“.$install.”、“.$flashvars.”、“.$params.”、“.$attributes.”;);
返回$ret;
}
}
?>
只需按照错误提示执行操作:检查app/views/helpers/flash.php第155行,查看输出的内容并进行修复。必须有一些代码输出某些内容。这可能是返回语句之一吗
if (is_object($view)) {
$view->addScript($this->Javascript->link('swfobject'));
return true;
} else {
return $this->Javascript->link('swfobject');
}
$ret .= $this->Javascript->codeBlock(
'swfobject.embedSWF
("'.$swfLocation.'", "'.$divDomId.'", "'.$width.'", "'.$height.'", "'.$version.'",
"'.$install.'", '.$flashvars.', '.$params.', '.$attributes.');');
return $ret;
}
页面上还有什么调用flash的代码?第155行是flash.php中的最后一行,即php(?>)的结束标记。在此之前,是嵌入SWF的代码。我看不出有任何错误。