Foros del Web » Programando para Internet » PHP »

Warning: Cannot modify header information - headers already sent by

Estas en el tema de Warning: Cannot modify header information - headers already sent by en el foro de PHP en Foros del Web. buenos días, al enviar el formulario me devuelve un error: Warning: Cannot modify header information - headers already sent by ... on line 23 a ...
  #1 (permalink)  
Antiguo 27/05/2014, 04:19
 
Fecha de Ingreso: julio-2002
Mensajes: 813
Antigüedad: 21 años, 8 meses
Puntos: 2
Warning: Cannot modify header information - headers already sent by

buenos días,

al enviar el formulario me devuelve un error:
Warning: Cannot modify header information - headers already sent by ... on line 23

a que puede ser debido?

Código PHP:
Ver original
  1. <?php
  2. //get unique id
  3. $up_id = uniqid();
  4. ?>
  5.  
  6. <?php
  7.  
  8. //process the forms and upload the files
  9. if ($_POST) {
  10.  
  11. //specify folder for file upload
  12. $folder = "uploads/";
  13.  
  14. //specify redirect URL
  15. $redirect = "upload.php?success";
  16.  
  17. //upload the file
  18. move_uploaded_file($_FILES["file"]["tmp_name"], "$folder" . $_FILES["file"]["name"]);
  19.  
  20. //do whatever else needs to be done (insert information into database, etc...)
  21.  
  22. //redirect user
  23. header('Location: '.$redirect); die;
  24. }
  25. //
  26.  
  27. ?>
  28.  
  29. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  30. <html xmlns="http://www.w3.org/1999/xhtml">
  31. <head>
  32. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  33. <title>Upload your file</title>
  34.  
  35. <!--Progress Bar and iframe Styling-->
  36. <link href="style_progress.css" rel="stylesheet" type="text/css" />
  37.  
  38. <!--Get jQuery-->
  39. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
  40.  
  41. <!--display bar only if file is chosen-->
  42. <script>
  43.  
  44. $(document).ready(function() {
  45. //
  46.  
  47. //show the progress bar only if a file field was clicked
  48.     var show_bar = 0;
  49.     $('input[type="file"]').click(function(){
  50.         show_bar = 1;
  51.     });
  52.  
  53. //show iframe on form submit
  54.     $("#form1").submit(function(){
  55.  
  56.         if (show_bar === 1) {
  57.             $('#upload_frame').show();
  58.             function set () {
  59.                 $('#upload_frame').attr('src','upload_frame.php?up_id=<?php echo $up_id; ?>');
  60.             }
  61.             setTimeout(set);
  62.         }
  63.     });
  64. //
  65.  
  66. });
  67.  
  68. </script>
  69.  
  70. </head>
  71.  
  72. <body>
  73. <h1>Upload your file </h1>
  74.  
  75. <div>
  76.   <?php if (isset($_GET['success'])) { ?>
  77.   <span class="notice">Your file has been uploaded.</span>
  78.   <?php } ?>
  79.   <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  80.     Name<br />
  81.     <input name="name" type="text" id="name"/>
  82.     <br />
  83.     <br />
  84.     Your email address <br />
  85.     <input name="email" type="text" id="email" size="35" />
  86.     <br />
  87.     <br />
  88.     Choose a file to upload<br />
  89.  
  90. <!--APC hidden field-->
  91.     <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
  92. <!---->
  93.  
  94.     <input name="file" type="file" id="file" size="30"/>
  95.  
  96. <!--Include the iframe-->
  97.     <br />
  98.     <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
  99.     <br />
  100. <!---->
  101.  
  102.     <input name="Submit" type="submit" id="submit" value="Submit" />
  103.   </form>
  104.   </div>
  105.  
  106. </body>
  107.  
  108. </html>

un saludo,
josé carlos.
  #2 (permalink)  
Antiguo 27/05/2014, 04:41
Avatar de pzin
Moderata 😈
 
Fecha de Ingreso: julio-2002
Ubicación: Islas Canarias
Mensajes: 10.488
Antigüedad: 21 años, 8 meses
Puntos: 2114
Respuesta: Warning: Cannot modify header information - headers already sent by

No cierres las etiquetas de PHP como haces en la linea #4 ya que así estás enviando datos —aunque sea un espacio o un salto de linea— al navegador antes de usar header(). Además tampoco tiene mucho sentido que lo cierres si el código que le sigue, sigue siendo PHP.

Etiquetas: formulario, header, headers, html, information, modify, warning
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 13:40.