Reputation: 7758
I have a very simple web app I am building. no php - just html & javascript.
I want to get this use case for user who comes to my site:
since I am clueless in file management - I'd be happy to get a tip where to start advice on js libraries that manage that or general information about that.
thank, Alon
p.s searching the web for "upload files" gave me a lot of result on how to upload files to ftp - my question is not about that.
Upvotes: 3
Views: 1716
Reputation: 63719
What you seem to be asking for typically requires server side code like php.
Having said that, there are some ways to do this with just JavaScript. The code will be largely browser-specific and generate a security warnings when saving (as it's typically unsafe to let JavaScript use resources like this). Specifically, I remember TiddlyWiki, which works with just JavaScript and HTML. Have a look at the code in such a TiddlyWiki file, there's code in there like this:
// Returns null if it can't do it, false if there's an error, true if it saved OK
function mozillaSaveFile(filePath,content)
{
if(window.Components) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if(!file.exists())
file.create(0,0x01B4);// 0x01B4 = 0664
var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
out.init(file,0x22,0x04,null);
out.write(content,content.length);
out.flush();
out.close();
return true;
} catch(ex) {
return false;
}
}
return null;
}
As an alternative, depending on the browsers you need to support, you could look into HTML5's local storage capabilities.
Upvotes: 1