The problem is, i want to save a text file (or anything) in the local system using javascript.
Asked
Active
Viewed 1,106 times
0
-
2javascript does not have access to the file system. This is not possible. – Amir Raminfar Aug 17 '11 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? – TJHeuvel Aug 17 '11 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. – shahalpk Aug 17 '11 at 20:23
-
related: http://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file – Justin ᚅᚔᚈᚄᚒᚔ Aug 17 '11 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. – zzzzBov Aug 17 '11 at 20:35
-
See http://stackoverflow.com/questions/1087246/can-javascript-access-a-filesystem – Ruan Mendes Aug 17 '11 at 21:07
2 Answers
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.
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');

Ruan Mendes
- 90,375
- 31
- 153
- 217