0

The problem is, i want to save a text file (or anything) in the local system using javascript.

6
  • 2
    javascript does not have access to the file system. This is not possible. Commented Aug 17, 2011 at 20:21
  • Indeed, but you can store data through other means. Is it just arbitrary data you'd want to store, or do you actually need a file somewhere? Commented Aug 17, 2011 at 20:21
  • like once the user have completed writing in an input box in the page, i want to give them the option to save as text file. Commented Aug 17, 2011 at 20:23
  • related: stackoverflow.com/questions/2897619/… Commented Aug 17, 2011 at 20:29
  • 1
    @Amir Raminfar, you're incorrect actually. Some browsers have a filesystem API, however most require that the page be loaded from a file:// path to use it. Commented Aug 17, 2011 at 20:35

2 Answers 2

1

You can't write to the user's file system. But you initiate a file download that the user can then save wherever they'd like.

In PHP, you can just use

header('Content-Disposition: attachment; filename=file.txt'); 
echo('File contents');
Sign up to request clarification or add additional context in comments.

Comments

1

There is no practical real world way to create a local file. However if you want to to just store data locally then try these two methods.

The old way:

http://www.w3schools.com/js/js_cookies.asp

The new way:

http://diveintohtml5.ep.io/storage.html

Alternatively, you could create a file with php and serve it out to the user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.