Foros del Web » Programando para Internet » PHP »

Importar archivo .txt a text area

Estas en el tema de Importar archivo .txt a text area en el foro de PHP en Foros del Web. Amigos...junto con saludarles, les pido ayuda con un formulario que tengo (mitad php y mitad html), en el cual debo importar una seria de archivos ...
  #1 (permalink)  
Antiguo 22/09/2008, 15:04
Avatar de pablosky13  
Fecha de Ingreso: septiembre-2008
Mensajes: 42
Antigüedad: 15 años, 7 meses
Puntos: 0
Importar archivo .txt a text area

Amigos...junto con saludarles, les pido ayuda con un formulario que tengo (mitad php y mitad html), en el cual debo importar una seria de archivos txt, escogiéndolos con un botón de opción y un botón "importar".
El problema es que no importa nada.

formulario.php

Código PHP:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Editor de texto</title>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">
<!--
.Estilo1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.Estilo7 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
body {
    background-color: #F5F5F5;
}
-->
</style>
</head>

<body>
<?php
//include("codigo-plus.php");
if(imp) { 

$op=$_REQUEST['op'];

switch (
$op) {
    case 
"actualidad":  
$actua file_get_contents("actualidad.txt"); 
$actua ucfirst($actua);
$actua nl2br($actua);
echo 
"listo!";
    break;
       
    case 
"noticias":  
$noti file_get_contents("noticias.txt");
$noti ucfirst($noti);
$noti nl2br($noti);
echo 
"listo!";
    break; 

    case 
"deportes":  
$depo file_get_contents("deportes.txt");
$depo ucfirst($depo);
$depo nl2br($depo);
echo 
"listo!";
    break;
       }    
    
    }
?>

<form action="codigo-plus.php" method="REQUEST">
  <label>  </label>
  <table border="0" cellspacing="3" cellpadding="0">
    <tr bordercolor="2">
      <td><span class="Estilo1">EDITOR DE TEXTO</span></td>
      <td rowspan="9" class="Estilo3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><label>
        <input type="radio" name="op" id="actualidad" value="actualidad">
      <span class="Estilo7">Actualidad</span></label></td>
    </tr>
    <tr>
      <td><label>
        <input type="radio" name="op" id="noticias" value="noticias">
      <span class="Estilo7">Noticias</span></label></td>
    </tr>
    <tr>
      <td><label>
        <input type="radio" name="op" id="deportes" value="deportes">
        <span class="Estilo7">Deportes</span>
      </label></td>
    </tr>
    <tr>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="33%">&nbsp;</td>
          <td width="67%"><label>
          <input onClick="#" type="submit" value="Importar texto" name="imp"
  style="BORDER: rgb(128,128,128) 1px dashed; FONT-SIZE: 8pt; FONT-FAMILY: Verdana; 
         BACKGROUND-COLOR: rgb(213,213,213)">
          </label></td>
        </tr>
      </table>      
      <label></label></td>
    </tr>
    <tr>
      <td><textarea name="contenido" id="contenido" cols="100" rows="25" style="font-family:Arial, Helvetica, sans-serif; font-size:10px" value="<?echo $actua;?>"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    
    <tr>
      <td><table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><input onClick="#" type="submit" value="Enviar" name="enviar"
  style="BORDER: rgb(128,128,128) 1px dashed; FONT-SIZE: 8pt; FONT-FAMILY: Verdana; 
         BACKGROUND-COLOR: rgb(213,213,213)"></td>
            <td><label></label>
              <table width="333" border="0" cellspacing="6" cellpadding="0">
                <tr>
                  <td width="51">&nbsp;</td>
                  <td width="52"><input onClick="#" type="reset" value="Borrar" name="boton"
  style="BORDER: rgb(128,128,128) 1px dashed; FONT-SIZE: 8pt; FONT-FAMILY: Verdana; 
         BACKGROUND-COLOR: rgb(203,203,203)"></td>
                  <td width="10"><label>
                    <input type="text" name="estado_de_noticia" id="estado de noticia" >
                  </label></td>
                </tr>
              </table></td>
          </tr>
      </table></td>
    </tr>
  </table>
  <label><br>
  <br>
  </label>
  <p><label></label>
  </p>
</form>

</body>
</html>
ayuda porfavor..
GRACIAS
  #2 (permalink)  
Antiguo 22/09/2008, 15:08
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Importar archivo .txt a text area

Código PHP:
if(imp) { 
Probablemente te falte el $.
  #3 (permalink)  
Antiguo 22/09/2008, 15:24
Avatar de pablosky13  
Fecha de Ingreso: septiembre-2008
Mensajes: 42
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Importar archivo .txt a text area

pero si (imp) es solo el boton name.....del boton importar, no deberia tener ese signo, ya que no es variable.
o de todas formas lo deberia tener?
  #4 (permalink)  
Antiguo 23/09/2008, 01:22
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Importar archivo .txt a text area

O_O Si, si es una variable del tipo:
$_POST['imp']

Si pones solamente $imp y te funciona es porque tienes register_globals ON. Se recomienda tenerlas apagadas por seguridad.
  #5 (permalink)  
Antiguo 23/09/2008, 13:54
Avatar de pablosky13  
Fecha de Ingreso: septiembre-2008
Mensajes: 42
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Importar archivo .txt a text area

mmmm, cambie esa parte pero no resulta, tu sabes como hacerlo?
Gracias por tu ayuda
  #6 (permalink)  
Antiguo 23/09/2008, 14:18
Avatar de Carlojas  
Fecha de Ingreso: junio-2007
Ubicación: Shikasta
Mensajes: 1.272
Antigüedad: 16 años, 10 meses
Puntos: 49
Respuesta: Importar archivo .txt a text area

Que tal pablosky13, tu problema radica en el método de envio de tu formulario que debe ser GET o POST, ya que el array superglobal REQUEST lo que hace es rescatar variables que sean enviadas por GET y POST. Variables Predefinidas. Ademas si tu página se autoprocesa debes indicarlo en el action del formulario prueba así tu código:
Código PHP:
<?php if($_POST['imp']) {  

$op $_POST['op']; 

switch (
$op) { 
    case 
"actualidad":   
$actua file_get_contents("actualidad.txt");  
$actua ucfirst($actua); 
$actua nl2br($actua); 
echo 
"listo!"
    break; 
        
    case 
"noticias":   
$noti file_get_contents("noticias.txt"); 
$noti ucfirst($noti); 
$noti nl2br($noti); 
echo 
"listo!"
    break;  

    case 
"deportes":   
$depo file_get_contents("deportes.txt"); 
$depo ucfirst($depo); 
$depo nl2br($depo); 
echo 
"listo!"
    break; 
       }     
     
    } 
?> 
// Metodo de envio post 
<form action="action="<?php $_SERVER['PHP_SELF'];?>" method="post">
Saludos.
  #7 (permalink)  
Antiguo 28/09/2008, 12:17
Avatar de pablosky13  
Fecha de Ingreso: septiembre-2008
Mensajes: 42
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Importar archivo .txt a text area

Hola Carlojas, muchas gracias por tu ayuda, pero el problema es que mi pagina tb tiene codigo en un archivo externo.
Mi caso es algo complicado, ya que ademas de importar el contenido de un archivo .txt, tengo ke reenviarlo a tal.....algo asi como actualizar un txt desde ese formulario, y el codigo para "actualizar" esta en un archivo externo......por eso....el action me produjo errores.

De todas formas gracias....y si tienes la solucion para mi gran problema estare agredecido
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 21:53.