Page 1 of 1

Update File....

Posted: Wed Apr 26, 2006 4:01 pm
by Maluendaster
I need to edit a file, by adding text at the end, for example...

1
2
3
4
5

If i want to add the number six, it should write under 5, but it writes like this..

1 2 3 4 5

Don't know what I'm doing wrong...

This is the Code

actu_cat.php :

Code: Select all

<?php
include ('config.php');
include ('admin.php');
?>


<div align="center"><font color="#999999" size="3" face="Verdana, Arial, Helvetica, sans-serif">Agregar
Nueva Categoria</font></div>
<form name="form1" method="post" action="proc_actu_cat.php">
  <p>
    <center>
      <input name="cat" type="text" id="cat">
      <br>
      <input type="submit" name="Submit" value="Agregar Categoria">
</center>
</p>
</form>
proc_actu_cat.php :( I know it has something to do with this fopen($archivo, 'a+'); )

Code: Select all

<?
include('config.php');
include('admin.php');
$form = $_POST['cat'];
$contenido = "$form <br>";
$archivo = "cat.php";
fopen($archivo, 'a+');
if (is_writable($archivo)) {
   if (!$handle = fopen($archivo, 'a')) {
         echo "No se puede abrir el archivo -> ($archivo)";
         exit;
   }

   if (fwrite($handle, $contenido) === FALSE) {
       echo "No se puede escribir la fila -> ($archivo)";
       exit;
   }
  
   echo "<center><font color=white size=5>Actualizado!</font>";
  
   fclose($handle);

} else {
   echo "El archivo $archivo no es de escritura!";
}
?>

Posted: Wed Apr 26, 2006 5:52 pm
by ambivalent
You need to write a CRLF to the file, not <br>

Code: Select all

$contenido = "$form \r\n";

Posted: Wed Apr 26, 2006 10:35 pm
by Maluendaster
ambivalent wrote:You need to write a CRLF to the file, not <br>

Code: Select all

$contenido = "$form \r\n";
thank you! it worked... btw , what is a CRLF??? I'm learning... :D Another question, what's the $handle Variable for??? , i copy and edit this from php.net....

Posted: Wed Apr 26, 2006 10:39 pm
by Maluendaster
and what if i want to edit the file to delete a line, the file is like this...
1
2
3
4
5

but i want to delete, for example, the number 3 ,and leave the file like this
1
2
4
5

What should I do????

Posted: Wed Apr 26, 2006 11:05 pm
by feyd
pretty much, you have to rewrite the entire file.

Posted: Wed Apr 26, 2006 11:52 pm
by Maluendaster
feyd wrote:pretty much, you have to rewrite the entire file.
then i guess that's not an option, don't know how to do that. :oops: