Ver Mensaje Individual
  #16 (permalink)  
Antiguo 09/09/2008, 21:43
Avatar de pepeverastegui
pepeverastegui
 
Fecha de Ingreso: septiembre-2008
Ubicación: Pedernales, Michoacan
Mensajes: 82
Antigüedad: 16 años, 6 meses
Puntos: 2
Respuesta: Como importar archivos a un textarea ?

ahora si compa ya estufas con esto ps mira lo qeu hice fue crear 3 archivos
crear.php para la creacion de ficheros mediante un textarea
abrir.php para abrir los ficheros ya sea lectura o escritura y en base a eso poder o no modificar
modificar que este unicamente se habre mediante un enlace en el archivo abrir y se modifica

CREAR.PHP
Código HTML:
<html>
<head>
<title>CREAR</title>
</head>
<body>
<form method=post action=crear.php>
<textarea cols=80 rows=10 name=datos></textarea><br><br>
NOMBRE Y RUTA DEL ARCHIVO A CREAR: <input type=text name=ruta><br>
<input type=submit name=b1 value=CREAR>
</form>
</body>
</html>

<?php
if($_POST[b1])
{
   file_put_contents($_POST[ruta], $_POST[datos]);
}
?> 
ABRIR.php
Código HTML:
<html>
<head>
<title>ABRIR</title>
<script>
function pasar()
{
   var cadena = document.f1.datos.value
   var texto = document.f1.ruta.value
   if(document.f2.escrito)
   {
      document.f2.escrito.value = cadena;
      document.f2.ubicacion.value = texto;
   }
}
</script>
</head>
<body>
<form name=f1 method=post action=abrir.php>
RUTA: <input type=text name=ruta value="<?= $_POST[ruta] ?>"><br>
TIPO: <select name=op>
<option value="l">LECTURA</option>
<option value="e">ESCRITURA</option>
</select>
<input type=submit name=b1 value=CARGAR><br>

<?php
if($_POST[ruta])
{
   $dir = $_POST[ruta];
   if($_POST[op] == "e")
   {
      $archivo = fopen($dir, "rw");
      $lectura = "no";
   }
   else
   {
      $archivo = fopen($dir, "r");
      $lectura = "si";
   }
   $contenido = fread($archivo, filesize($dir));

?>

<textarea cols=80 rows=10 name=datos><?= $contenido ?></textarea><br>
</form>
<form name=f2 method=post action=modificar.php onsubmit="return pasar()">

<?php
   if($lectura == "si")
   {
?>

<input type=button name=b2 value=MODIFICAR disabled>

<?php
   }
   else
   {
?>

<input type=submit name=b2 value=MODIFICAR>
<input type=hidden name=escrito>
<input type=hidden name=ubicacion>

<?php
   }
}
?>

</body>
</html> 
MODIFICAR.PHP
Código HTML:
<?php
file_put_contents($_POST[ubicacion], $_POST[escrito]);
?> 
saludos y suerte