Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/07/2010, 14:07
Avatar de djcandido
djcandido
 
Fecha de Ingreso: junio-2009
Ubicación: San Salvador
Mensajes: 50
Antigüedad: 14 años, 10 meses
Puntos: 0
Error de header(); [RESUELTO]

Saludos, tengo un problema con la redireccion de una pagina web. Yo estoy haciendo un sistema de la siguiente forma:
pagina1.php: tiene el formulario. pagina2.php: procesa el formulario. pagina3.php: siguiente pagina despues de procesar los datos (que no es resultado, sino otro formulario con otros campos diferentes).

El detalle es que me da un error en la pagina2.php de header:

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\sipe\clases\cThumbnail.class.php:14 5) in C:\AppServ\www\sipe\internos\internos_process.php on line 85

Creo que el error me lo da por que el servidor ya hizo una escritura (un upload de una foto que esta en la pagina1.php)

Codigo pagina1.php
Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modulo de Internos - Fotos</title>
<link href="/sipe/css/style.css" rel="stylesheet" type="text/css" />
<!--script language="javascript" src="/sipe/js/popup.js"></script-->
<script>
var parametro;
function popup()
{
parametro = window.open("buscar_interno2.php","","width=600,height=500,scrollbars=yes");
parametro.document.getElementById('1').value = "nome" ;
parametro.document.getElementById('2').value = "num" ;
}
</script>
</head>

<body>

<?php include("../encabezado.php"); ?>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>
    <span class="preload17a"></span>
<span class="preload17b"></span>
<ul class="menu17">
<li><a href="http://www.forosdelweb.com/f18/"><b>Inicio</b></a></li>
<li><a href="./reportes/reportes.php"><b>Búsquedas y Reportes</b></a></li>
<li class="current"><a href="./internos/internos.php"><b>Internos</b></a></li>
<li><a href="http://www.forosdelweb.com/f18/penales/penales.php"><b>Centros Penales</b></a></li>
<li><a href="http://www.forosdelweb.com/f18/penas-delitos/penas.php"><b>Penas y Delitos</b></a></li>
<li><a href="http://www.forosdelweb.com/f18/juzgados/juzgados.php"><b>Juzgados</b></a></li>
<!--li><a href="#nogo"><b>Reportes</b></a></li-->
<li><a href="http://www.forosdelweb.com/f18/usuarios/usuarios.php"><b>Usuarios</b></a></li>
<li><a href="http://www.forosdelweb.com/f18/cerrar_sesion.php"><b>Cerrar Sesion</b></a></li>
</ul>
</td>
  </tr>
</table>
<table width="900" height="255" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="40" height="40" class="sup_izq">&nbsp;</td>
    <td class="sup">&nbsp;</td>
    <td width="40" class="sup_der">&nbsp;</td>
  </tr>
  <tr>
    <td height="175" class="izq">&nbsp;</td>
    <td bgcolor="#FFFFFF">
      <table width="600" border="0" align="center">
  <tr>
    <td><div class="animatedtabs">
<ul>
<li><a href="internos.php" title="Administración de Datos Personales"><span>Datos Personales</span></a></li>
<li class="selected"><a href="fotos.php" title="Administración de Fotos"><span>Foto</span></a></li>
<li><a href="./datos_juridicos.php" title="Administración de Datos Jurídicos"><span>Datos Jurídicos</span></a></li>
<li><a href="traslados.php" title="Administración de traslados"><span>Traslado</span></a></li>
<li><a href="incidencias.php" title="Administración de Incidencias"><span>Incidencias</span></a></li>
<li><a href="./datos_historicos.php" title="Administración de datos históricos"><span>Histórico</span></a></li>
</ul>
</div></td>
  </tr>
</table>
    <strong>Asignar nueva foto</strong>
    <form action="internos_process.php" method="post" enctype="multipart/form-data" name="frm_foto" id="frm_foto">
        <table width="450" border="0" align="center">
          <tr>
            <td align="right">Asignar foto a:</td>
            <td align="center"><input name="txt_id" type="text" id="txt_id" size="2" />
              <input name="txt_nombre_interno" type="text" id="txt_nombre_interno" value="<?php echo($_SESSION["pnombre"]." ".$_SESSION["snombre"]." ".$_SESSION["tnombre"]." ".$_SESSION["papellido"]." ".$_SESSION["sapellido"]." ".$_SESSION["apellidocasada"]);?>" size="45" readonly="readonly"/>
            <a href="#"><img src="/sipe/img/advanced_search.gif" alt="Buscar" width="20" height="16" border="0" longdesc="Buscar" onClick="popup()" /></a></td>
          </tr>
          <tr>
            <td align="right">Foto:</td>
            <td align="center"><input name="imagen" type="file" id="imagen" value="" size="32" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td align="center"><p class="button">
              <input name="statement" type="hidden" id="statement" value="insert" />
              <input name="step" type="hidden" id="step" value="2" />
              <!--input name="upload" type="hidden" id="upload" value="upload" /-->
            <input type="submit" name="Submit" value="upload" /></p></td>
          </tr>
          <tr>
            <td colspan="2" align="center"><!--input type="submit" name="btn_guardar" id="btn_guardar" value="upload" /--></td>
          </tr>
        </table>
    </form></td>
    <td class="der">&nbsp;</td>
  </tr>
  <tr>
    <td height="40" class="inf_izq">&nbsp;</td>
    <td class="inf">&nbsp;</td>
    <td class="inf_der">&nbsp;</td>
  </tr>
</table>
</body>
</html> 
Codigo pagina2.php:
Código PHP:
<?php
session_start
();
//require("../clases/cLeerEscribirArchivo.class.php");
require("../clases/cThumbnail.class.php");
//$lea = new LeerEscribirArchivo;
$statement $_SESSION["statement"] = $_POST['statement'];
$step $_POST['step'];
$upload  $_POST['upload'];

switch(
$statement){
    case(
"insert"):
        if(
$step=="1"){
            
$_SESSION["pnombre"] = $_POST['txt_pnombre'];
            
$_SESSION["snombre"] = $_POST['txt_snombre'];
            
$_SESSION["tnombre"] = $_POST['txt_tnombre'];
            
$_SESSION["papellido"] = $_POST['txt_papellido'];
            
$_SESSION["sapellido"] = $_POST['txt_sapellido'];
            
$_SESSION["apellidocasada"] = $_POST['txt_tapellido'];
            
$_SESSION["conocidopor"] = $_POST['txt_conocidopor'];
            
$_SESSION["alias"] = $_POST['txt_alias'];
            
$_SESSION["fechnac"] = $_POST['lst_anio']."-".$_POST['lst_mes']."-".$_POST['lst_dia'];
            
$_SESSION["genero"] = $_POST['genero'];
            
$_SESSION["tipodoc"] = $_POST['lst_tipo_documento'];
            
$_SESSION["numdoc"] = $_POST['txt_num_doc'];
            
$_SESSION["nombrepapa"] = $_POST['txt_nom_papa'];
            
$_SESSION["nombremama"] = $_POST['txt_nom_mama'];
            
$_SESSION["nombreconyuge"] = $_POST['txt_nom_conyuge'];
            
$_SESSION["estadofamiliar"] = $_POST['lst_estado_familiar'];
            
$_SESSION["niveledu"] = $_POST['lst_nivel_edu'];
            
$_SESSION["profesion"] = $_POST['lst_profesion_oficio'];
            
$_SESSION["estadointerno"] = $_POST['lst_estado_interno'];
            
$_SESSION["pais"] = $_POST['lst_pais'];
            
$_SESSION["departamento"] = $_POST['lst_depto'];
            
$_SESSION["municipio"] = $_POST['lst_municipio'];
            
$_SESSION["direccion"] = $_POST['txt_direccion'];
            
//INSERTAR LOS DATOS INICIALES DEL INTERNO EXCEPTO LOS NOMBRES
            
header("Location: fotos.php");
            
        }elseif(
$step=="2"){
////////////////////COMIENZO A HACER EL UPLOAD///////////////
            
$_SESSION["idinternofoto"] = $_POST['txt_id'];
            
$_SESSION["nombreinternofoto"] = $_POST['txt_nombre_interno'];
            
$_SESSION["imagen"] = $_POST['imagen'];
                if(isset(
$_FILES["imagen"])) {
                    
$temp $_FILES["imagen"]["tmp_name"];
                    
$str "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
                    
$cad "";
                        for(
$i=0;$i<10;$i++) {
                            
$cad .= substr($str,rand(0,62),1);
                        }
                    
$thumb = new Thumbnail($temp);
                        if(
$thumb->error) {
                            echo 
$thumb->error;
                        } else {
                            
$thumb->resize(222);
                            
$fototomada $thumb->save_jpg("fotos/"$cad."_".date('dmY_His'));
                            echo(
$fototomada);
                            
//$thumb->save_jpg("", "imagen");
                            //insertar datos de foto a la base de datos
                          
}
                }
////////////////ESTE HEADER ME DA ERROR///////////////////
            
header("Location: datos_juridicos.php");
//////////////////////////////////////////////////////////////////////
        
}




        break;
    case(
"modify"):
    
    
        break;
    case(
"delete"):
    
    
        break;
    default:
        echo(
"nada");
    }

        echo(
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Untitled Document</title>
<link href=\"/sipe/css/style.css\" rel=\"stylesheet\" type=\"text/css\" />
</head>

<body>
</body>
</html>"
);
?>
La funcion con la que se sube la foto es la siguiente:
Código PHP:
public function save_jpg($dir$name$quality 95) {
            
$path $dir $name image_type_to_extension(IMAGETYPE_JPEG);
            
imagejpeg($this->thumbnail$path$quality);
            
            
imagedestroy($this->thumbnail);
            return 
$path;
        } 
Lastimosamente no puedo colocar mas codigo porque no me permite este foro, yo sé que para hacer un header no hay que hacer una escritura antes, y una posible solucion es que envie los datos de la pagina1 a la pagina3 directamente y que la pagina3 procese los datos, pero no quiero hacerlo por que para eso estoy haciendo un archivo intermedio de procesos donde están todas las ejecuciones a la base de datos y allí llegarían todos los datos de los formularios, los cuales los capturo con switch case, if elseif.

Este es el comprimido con los archivos en cuestion:

[URL="http://www.4shared.com/file/7dpfCRsY/_2__zip.html"]http://www.4shared.com/file/7dpfCRsY/_2__zip.html[/URL]

Gracias

Última edición por djcandido; 05/07/2010 a las 14:54 Razón: Resuelto