Foros del Web » Programando para Internet » PHP »

Grabar datos en php

Estas en el tema de Grabar datos en php en el foro de PHP en Foros del Web. Buenas necesito que me ayuden a guardar lo que fuera que inserte en un campo de texto y que en un archivo .txt no se ...
  #1 (permalink)  
Antiguo 03/03/2011, 14:14
 
Fecha de Ingreso: septiembre-2010
Ubicación: Chiclayo
Mensajes: 17
Antigüedad: 13 años, 8 meses
Puntos: 1
Grabar datos en php

Buenas necesito que me ayuden a guardar lo que fuera que inserte en un campo de texto y que en un archivo .txt no se borre, mi codigo es el siguiente:
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form action="PruebaFicheros.php" method="post">
Ingrese lo que desea guardar: <input type="textbox" name="Caja" size="50">
<input type="submit" value="Crear y Guardar">
</form>
<?php
function escribir($path1,$escritura){
$gestor=fopen($path1,"w+");
$texto=fwrite($gestor,$escritura);
//cerramos el archivo
fclose($gestor);
}
?>
<?
$path1="C:\AppServ\www\appserv\ficherosphp\fichero Prueba.txt";
$fecha = date ( "h:i:s:A ");
$outstring = $fecha.$_POST["Caja"];
escribir($path1,$outstring);


?>



</body>
</html>

Y necesito grabar y que se guarde lo que he grabado, porque hasta aqui tan solo graba si le doy a "Crear y Grabar" pero para la proxima se borra lo anterior y necesito que se quede lo anterior. Gracias por la ayuda. =)
  #2 (permalink)  
Antiguo 03/03/2011, 14:21
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
Respuesta: Grabar datos en php

La cuestion esta aca:

$gestor=fopen($path1,"w+");

Fijate lo de w+:
http://php.net/manual/en/function.fopen.php

Cita:
'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
Usa: 'a'
así: $gestor=fopen($path1,"a");

Etiquetas: Ninguno
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 22:22.