Smelis
Smelis

Reputation: 43

The simpliest way to store data on pc

I'm creating a page for myself that could be accessed without internet connection (local storage only).

I want that page to somehow store data (that I put in the website) on my computer.

I've heard there are ways to edit .txt files with a help of php? Also maybe Chrome could somehow save that info easier?

Appreciate any help

EDIT: I want a fast and easy access to a website via Chrome only, so I prefer not to be using XAMPP or any other software.

Upvotes: 1

Views: 1620

Answers (3)

Shomz
Shomz

Reputation: 37701

The easiest way would be to use HTML5's localStorage (no server-side languages needed), but it won't be easy to get that data outside of your page (I understood you'll be using that offline page which has stored data).

It's as simple as:

window.localStorage.setItem('myItem', 'Hello World');

And then to get it, you'd just do:

window.localStorage.getItem('myItem');

Array approach works as well (localStorage.myItem, etc.).

Read more about it here and here.

Here is a simple example from above: http://jsfiddle.net/h6nz1Lq6/

Notice how the text remains even after you remove the setter line and rerun the script (or just go to this link: http://jsfiddle.net/h6nz1Lq6/1/).

The downside of this approach is that the data can easily be cleared by accident (by clearing browser/website data, but again this is similar to accidental deleting of a file, so nothing to be afraid of if you know what you're doing) and that it doesn't work across browsers (each browser stores its own localStorage).


If you still decide to use a server-side language, there are millions of tutorials about them. For a beginner, it would probably be the easiest to use a simple PHP script to write a file, but that would require using a server on your machine.

Upvotes: 2

Microsis
Microsis

Reputation: 279

PHP example:

<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>

Taken from http://www.w3schools.com/php/func_filesystem_fwrite.asp

Upvotes: 1

Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26647

You can read and write directly to storage with PHP or use a database for i/o. Check in PHP+MySQL for a common solution and use file upload with HTML or textarea field for plain text.

Upvotes: 0

Related Questions