Katana24
Katana24

Reputation: 8959

Writing to a text file using Javascript

I want to write to a text file using javascript. I know that it is possible but there are some problems.

I am running a javascript program that calculates the location of an object (its latitude & longitude) which changes every 5 seconds; i want to write this information to a text file. The javascript program will soon run on a server and I'll use the information written to the text file to communicate with an Android app on my phone.

So, my question really is:

  1. How can it be done properly?

    I know that there may be some permission issues but considering it won't be online and available to others will it be a problem and, if it is, should I go with PHP to do what I want? I know ASP is more Microsoft orientated and I work with a Mac so PHP would be the preference here.

  2. When writing a file, is it possible to write to an existing file or does the process simply destroy and recreate the same file?

Upvotes: 2

Views: 9617

Answers (2)

SSH This
SSH This

Reputation: 1929

I would use PHP

http://www.php.net/

This has a good code example:

http://www.tizag.com/phpT/filewrite.php

Also, you can make the request using jQuery's AJAX function, this will allow to effectively run this code from javascript:

http://api.jquery.com/jQuery.ajax/

Upvotes: 3

Muhammad Abrar
Muhammad Abrar

Reputation: 2322

Using the latest HTML5 Javascript, you can use the FileSystem APIs to read/write/append to text files. This is a good tutorial here : Exploring the FileSystem APIs.

Upvotes: 2

Related Questions