Foros del Web » Programando para Internet » PHP »

PHP OO FPDF error: Some data has already been output, can't send PDF file

Estas en el tema de FPDF error: Some data has already been output, can't send PDF file en el foro de PHP en Foros del Web. Estoy creando un fortato con ayuda de la libreria fpdf sin embarga me tope con el siguiente error FPDF error: Some data has already been ...
  #1 (permalink)  
Antiguo 10/05/2011, 23:20
 
Fecha de Ingreso: noviembre-2010
Mensajes: 3
Antigüedad: 13 años, 5 meses
Puntos: 0
FPDF error: Some data has already been output, can't send PDF file

Estoy creando un fortato con ayuda de la libreria fpdf sin embarga me tope con el siguiente error

FPDF error: Some data has already been output, can't send PDF file

que solucione con el uso

ob_end_clean();

ya que uso varias includes todo esto corriendo bajo un servidor local Wampserver pff y funciona genera perfectamente el pdf a las mil maravillas


Código PHP:
    <?php
include('../../../../../clases/Bd.php');
include(
'../../../../../clases/permisos.class.php');
include(
'../../../../../clases/usuarios.class.php');
include(
'../../../../../clases/nomina.class.php');
include(
'../../../../../clases/pago.class.php');
include(
'../../../../../clases/imss.class.php');
include(
'../../../../../clases/comision.class.php');
include(
'../../../../funciones.php');



ob_end_clean();                           //limpia el buffer de salida para poder generar el pdf
include('../../../../../clases/fpdf.php');

            class 
PDF extends FPDF
                    
{
                            
//Cargar los datos
                    
function LoadData($file)
                    {
                        
//Leer las líneas del fichero
                        // $lines=file($file);
                        
$lines=$file;
                        
$data=array();
                        foreach(
$lines as $line)
                        
$data[]=explode(';',chop($line));
                        return 
$data;
                    }


                            
                    function 
Tabla($header,$data)
                    {
                            
//Anchuras de las columnas
                        
$w=array(45,45,45,45);
                    
                        
                        
//Datos
                    
                        
foreach($data as $filas)
                            {
                                 
                                    
$this->Cell($w[0]*4,7,$filas[0]."                            ".$filas[1],1,0,'C');
                                    
$this->Ln();
                                
                                for(
$i=0;$i<count($header);$i++)
                                
$this->Cell($w[$i]*2,6,$header[$i],1,0,'C');
                                
$this->Ln();
                                     
$total_p=$filas[2]+$filas[4]+$filas[6]+$filas[8]+$filas[10]+$filas[12]+$filas[14]+$filas[16];
                                     
$total_d=$filas[3]+$filas[5]+$filas[7]+$filas[9]+$filas[11]+$filas[13]+$filas[15];
                                     if(
$filas[2]==0$filas[2]="----------";else $filas[2]='$'.$filas[2];
                                     if(
$filas[3]==0$filas[3]="----------";else $filas[3]='$'.$filas[3];
                                    
$this->Cell($w[0],5,'SUELDO','LR');
                                    
$this->Cell($w[0],5,$filas[2],'LR');
                                    
$this->Cell($w[0],5,'INFONAVIT','LR');
                                    
$this->Cell($w[0],5,$filas[3],'LR');
                                    
                                    if(
$filas[4]==0$filas[4]="----------";else $filas[4]='$'.$filas[4];
                                    if(
$filas[5]==0$filas[5]="----------";else $filas[5]='$'.$filas[5];
                                    
$this->Ln();
                                    
$this->Cell($w[0],5,'VIATICOS','LR');
                                    
$this->Cell($w[0],5,$filas[4],'LR');
                                    
$this->Cell($w[0],5,'FONACOT','LR');
                                    
$this->Cell($w[0],5,$filas[5],'LR');
                                    
                                    
                                    if(
$filas[6]==0$filas[6]="----------";else $filas[6]='$'.$filas[6];
                                    if(
$filas[7]==0$filas[7]="----------";else $filas[7]='$'.$filas[7];
                                    
$this->Ln();
                                    
$this->Cell($w[0],5,'COM GANADEROS','LR');
                                    
$this->Cell($w[0],5,$filas[6],'LR');
                                    
$this->Cell($w[0],5,'DIF POLIZA','LR');
                                    
$this->Cell($w[0],5,$filas[7],'LR');

                                    if(
$filas[8]==0$filas[8]="----------";else $filas[8]='$'.$filas[8];
                                    if(
$filas[9]==0$filas[9]="----------";else $filas[9]='$'.$filas[9];
                                    
$this->Ln();
                                    
$this->Cell($w[0],5,'VACACIONES','LR');
                                    
$this->Cell($w[0],5,$filas[8],'LR');
                                    
$this->Cell($w[0],5,'MERCANCIA','LR');
                                    
$this->Cell($w[0],5,$filas[9],'LR');
                                     
                                     if(
$filas[10]==0$filas[10]="----------";else $filas[10]='$'.$filas[10];
                                    if(
$filas[11]==0$filas[11]="----------";else $filas[11]='$'.$filas[11];
                                      
$this->Ln();
                                    
$this->Cell($w[0],5,'PRIMA','LR');
                                    
$this->Cell($w[0],5,$filas[10],'LR');
                                    
$this->Cell($w[0],5,'PRESTAMO','LR');
                                    
$this->Cell($w[0],5,$filas[11],'LR');
                                    
                                       
                                       
                                    if(
$filas[12]==0$filas[12]="----------";else $filas[12]='$'.$filas[12];
                                    if(
$filas[13]==0$filas[13]="----------";else $filas[13]='$'.$filas[13];                                       
                                       
$this->Ln();
                                    
$this->Cell($w[0],5,'AGUINALDO','LR');
                                    
$this->Cell($w[0],5,$filas[12],'LR');
                                    
$this->Cell($w[0],5,'DEVOLUCION','LR');
                                    
$this->Cell($w[0],5,$filas[13],'LR');
                                    
                                     if(
$filas[14]==0$filas[14]="----------";else $filas[14]='$'.$filas[14];
                                     if(
$filas[15]==0$filas[15]="----------";else $filas[15]='$'.$filas[15];
                                     
$this->Ln();
                                    
$this->Cell($w[0],5,'FESTIVO','LR');
                                    
$this->Cell($w[0],5,$filas[14],'LR');
                                    
$this->Cell($w[0],5,'FALTAS','LR');
                                    
$this->Cell($w[0],5,$filas[15],'LR');
                                  
                                    if(
$filas[16]==0$filas[16]="----------";else $filas[16]='$'.$filas[16];
                                       
$this->Ln();
                                    
$this->Cell($w[0],5,'OTROS','LR');
                                    
$this->Cell($w[0],5,$filas[16],'LR');
                                    
$this->Cell($w[0],5,'','LR');
                                    
$this->Cell($w[0],5,$filas[17],'LR');
                                    
                                    
//subtotal de perceociones
                                    
                                      
                                    
$this->Ln();
                                    
$this->Cell($w[0],5,'TOTAL DE PERCEPCIONES','LR');
                                    
$this->Cell($w[0],5,'$'.$total_p,'LR');
                                    
$this->Cell($w[0],5,'TOTAL DE DEDUCCIONES','LR');
                                    
$this->Cell($w[0],5,'$'.$total_d,'LR');                                    
                                               
$this->Ln();
                                    
$neto=$total_p-$total_d;           
                             
$this->Cell($w[0]*4,4," NETO A RECIBIR \$".$neto,1,0,'C');        
                                    
$this->Ln();
                                    
$this->Cell(array_sum($w),0,'','T');
                                    
$this->Ln(6);
                            }
                        
//Línea de cierre
                        
                    
}

                    }
///recibiendo los datos mas importantes
if(isset($_GET['id_nomina']))
$id_nomina=$_GET['id_nomina'];
else
$id_nomina=NULL;

$imss=new Imss($id_nomina,'','','','','','','','','','');
$com=new Comision($id_nomina,'','','','','','','','','','','');
$nom=new Nomina($id_nomina,"","");
$reg_nom=$nom->consulta();
$reg_imss=$imss->consulta_xnomina();
$reg_com=$com->consulta_xnomina();
$i=0;$j=0;
foreach(
$reg_imss as $regimss)
{
     
$vector_imss[$i]=$regimss[1].';'.$regimss[2].';'.$regimss[3].';'.$regimss[4].';'.$regimss[5].';'.$regimss[6].';'.$regimss[7].';'.$regimss[8].';'.$regimss[9].';'.$regimss[10]; 
     
$i++;
}

foreach(
$reg_com as $regcom)
{
      
$vector_com[$j]=$regcom[2].';'.$regcom[3].';'.$regcom[4].';'.$regcom[5].';'.$regcom[6].';'.$regcom[7].';'.$regcom[8].';'.$regcom[9].';'.$regcom[10].';'.$regcom[11];
      
$j++;
}

for(
$z=0;$z<$i;$z++){
 list(
$id_usuario,$sueldo,$vacaciones,$prima,$ispt,$ims,$cred_sal,$infonavit,$fonacot,$sueldo_sa) = explode(";",$vector_imss[$z]);
 list(
$comision,$prestamo,$dif_poliza,$devolucion,$falta,$mercancia,$festivo,$aguinaldo,$otros,$viaticos) = explode(";",$vector_com[$z]);
  
$user = new Usuarios($id_usuario,'','','','','','','','','','','','','');
  
$trabajador=$user->consulta_nombre();
  
$hoy date("d-m-Y");
  
  if(
$sueldo_sa!=0){
   
$sueldo=$sueldo_sa;
  }else{
  
$sueldo=imss_ptotal($sueldo,$ispt,$ims,$cred_sal);
  }
   
$total_imss=imss_total($sueldo,$vacaciones,$prima,$ispt,$ims,$cred_sal,$infonavit,$fonacot); 
   
$total=NULL;
  
//$falta=100;
  
$datos[$z]=$trabajador.";".$hoy.";".$sueldo.";".$infonavit.";".$viaticos.";".$fonacot.";".$comision.";".$dif_poliza.";".$vacaciones.";".$mercancia.";".$prima.";".$prestamo.";".$aguinaldo.";".$devolucion.";".$festivo.";".$falta.";".$otros.";;".$total.";";
}



$pdf=new PDF();
//Títulos de las columnas
$cabecera=array('PERCEPCIONES','DEDUCCIONES');


//Carga de datos
$datos=$pdf->LoadData($datos);
$pdf->SetFont('Arial','',8);
$pdf->AddPage();
$pdf->Tabla($cabecera,$datos);
$pdf->Output();
?>
PERO AL MIGRARLO A UN SERVIDOR DE VERDAD POR DECIRLO A SI NO FUNCIONA ME TIRA EL SIGUIENTE ERROR

Warning: Cannot modify header information - headers already sent by (output started at /home/medicama/public_html/lacteos/clases/usuarios.class.php:125) in /home/medicama/public_html/lacteos/clases/fpdf.php on line 1017
FPDF error: Some data has already been output, can't send PDF file


QUE PODRA SER ? ? ?? DE ANTEMANO SE AGRADECE LA AYUDA
  #2 (permalink)  
Antiguo 11/05/2011, 08:33
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: FPDF error: Some data has already been output, can't send PDF file

El mensaje de error te indica exactamente donde estás provocando una salida prematura:
Cita:
headers already sent by (output started at /home/medicama/public_html/lacteos/clases/usuarios.class.php:125)
Solo pon atención al mensaje.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 11/05/2011, 09:01
Avatar de juankcres  
Fecha de Ingreso: septiembre-2009
Mensajes: 88
Antigüedad: 14 años, 7 meses
Puntos: 2
Respuesta: FPDF error: Some data has already been output, can't send PDF file

Si es que no me equivoco el error es el espacio en blanco que está antes de la etiqueta de php

Debes eliminar ese espacio en blanco dejarlo así
<?php
__________________
Sé fiel hasta la muerte, y yo te daré la corona de la vida.

Ap. 2:10
  #4 (permalink)  
Antiguo 11/05/2011, 10:30
 
Fecha de Ingreso: noviembre-2010
Mensajes: 3
Antigüedad: 13 años, 5 meses
Puntos: 0
Respuesta: FPDF error: Some data has already been output, can't send PDF file

muchas gracias por la respuesta ya solucione el problema ---------------------------------

en alguna de las inclusiones de las clases imprimia valores para comprobar su correcto funcionamiento y eso provoca los espacios en blanco que hacia que el fpdf no funcionara correctamente lo unico extraño es que bajo un servidor local funcionara bien
  #5 (permalink)  
Antiguo 10/11/2015, 14:57
 
Fecha de Ingreso: septiembre-2015
Ubicación: Piedra Blanca
Mensajes: 1
Antigüedad: 8 años, 7 meses
Puntos: 0
Gracias de todo corazon

Muchas gracias, por esta respuesta, ya estaba pensando buscar otra opcion, pues me estaba funcionando localmente, pero cuando lo subia a Servidor, me daba ese error..

Etiquetas: error-fpdf, fpdf
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:54.