Is it possible to make a comment box without Databases?

0

I was looking for if it is possible to make a section in which the comments are saved in a .txt, and every time you comment, this file is updated, only with javascript and php.

    
asked by Lisandro Di Meo 27.03.2018 в 01:45
source

1 answer

1

To your question if you can, Yes we can, just do it !! : 9

  

First things first, LOOK FOR GOOGLE:)

I'll write it in PHP.

Create new file and write, this about write the contents of the file

$file = fopen("archivo.txt", "w");
fwrite($file, "Esto es una nueva linea de texto" . PHP_EOL);
fwrite($file, "Otra más" . PHP_EOL);
fclose($file);

Create new file and write, this edits (Not over write) file content

    $file = fopen("archivo.txt", "a");
    fwrite($file, "Añadimos línea 1" . PHP_EOL);
    fwrite($file, "Añadimos línea 2" . PHP_EOL);
    fclose($file);

Read the file

    if (file_exists('archivo.txt')) {
        $file = fopen("archivo.txt", "r");
        while (!feof($file)) {
            echo fgets($file) . "<br />";
        }
        fclose($file);
    } else {
        echo 'file no exist';
    }
    
answered by 27.03.2018 / 17:42
source