D
D
dsomni2020-12-20 20:11:35
Node.js
dsomni, 2020-12-20 20:11:35

How to save data from html form to computer?

Good day

I want to upload data from the html form to a text file on the local machine. I've already tried a lot of things - it doesn't help:

1. require(fs) does not work in the browser, as I understand it
2. require(browserify-fs) saves the file, but in virtual memory, again, if I understand correctly
3. the only way out is - php a script that for some reason does not want to work. Trying to fix - in vain (complete zero in php)

program.php

<?php
    $title = $_POST["channel0Title"]; //You have to get the form data
    $gain = $_POST["channel0Gain"];
    $offset = $_POST["channel0Offset"];
    $file = fopen('1.txt', 'w'); //Open your .txt file
    ftruncate($file, 0); //Clear the file to 0bit
    $content = $title. PHP_EOL .$gain. PHP_EOL .$offset;
    fwrite($file , $content); //Now lets write it in there
    //file_put_contents($file , $content);
    fclose($file ); //Finally close our .txt
    die(header("Location: ".$_SERVER["HTTP_REFERER"]));
?>


main.html
<form action="public\scripts\program.php" method="post">
            Channel 8 Title:<br><input type="text" name="channel0Title" value="Channel 7"><br>
            Gain:<br><input type="text" name="channel0Gain" value="4.000"><br>
            Offset:<br><input type="text" name="channel0Offset" value= "6.000"><br>
            <input type="submit" id ="submitButton" value="Submit">
        </form>


Gives an error Cannot POST /public/scripts/program.php

Please help me figure out why the script is not working
Or give advice on what framework / language to use to facilitate data exchange between the server and the client

Thanks in advance!

PS I'm using node.js so I'm loading program.php as a static file

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question