Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read/write local files through a web page?

I am writing a html based app, and want to store and retrieve data from local file. This app will not be hosted on a web server.

Can anyone please help enlighten the topic on how can this be done?

like image 637
praneybehl Avatar asked Aug 19 '12 02:08

praneybehl


People also ask

Can a website access local files?

Web browsers (and JavaScript) can only access local files with user permission. To standardize the file access from the browser, the W3C published the HTML5 File API in 2014. It defines how to access and upload local files with file objects in web applications.

How do I view local files in my browser?

Using Google Chrome to access local files is as easy as pressing Ctrl + O at the same time. This interface will open, allowing you to navigate to whichever file or folder is needed. There are several types of files which can be opened using Chrome. These include pdf, mp3 files, some video files and most document files.

How do I write to a Web page?

Click File > Save As and choose the location where you want to save your document. Name your file. In the Save as type list, choose Web Page, Filtered.


2 Answers

You should use FileSystem API of HTML5:

window.requestFileSystem(window.TEMPORARY, 5*1024*1024, function(){
    fs.root.getFile('test.dat', {}, function(fileEntry) {
        fileEntry.file(function(file) {
            // Here is our file object ... 
        });
    });
}, errorHandler);

Checkout FileSystem API for more reference

Visit The HTML5 Test to test browser support

like image 64
Daniil Ryzhkov Avatar answered Sep 19 '22 05:09

Daniil Ryzhkov


Try HTML 5 FileSystem API

Below links has details

http://dev.w3.org/2009/dap/file-system/pub/FileSystem/

http://www.html5rocks.com/en/tutorials/file/filesystem/

like image 39
Mathew Joseph Avatar answered Sep 20 '22 05:09

Mathew Joseph