The simpliest way to store data on pc

ⅰ亾dé卋堺 提交于 2019-12-25 03:45:16

问题


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.


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/26026374/the-simpliest-way-to-store-data-on-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!