[英]How do I allow the user to upload file to my site, edit it and save it back
I have a very simple web app I am building. 我正在构建一个非常简单的Web应用程序。 no php - just html & javascript.
没有php-只有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. 由于我对文件管理一无所知-我很高兴获得提示,以获取有关管理该库或有关该库的一般信息的js库的建议。
thank, Alon 谢谢,阿隆
ps 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. ps在网络上搜索“上传文件”给了我很多关于如何将文件上传到ftp的结果-我的问题不是这个。
What you seem to be asking for typically requires server side code like php. 您似乎要求的通常需要服务器端代码(例如php)。
Having said that, there are some ways to do this with just JavaScript. 话虽如此,但是有一些方法可以仅使用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 ).
该代码将主要针对浏览器,并且在保存时会生成安全警告( 因为让JavaScript使用此类资源通常是不安全的 )。 Specifically, I remember TiddlyWiki , which works with just JavaScript and HTML.
具体来说,我记得TiddlyWiki ,它仅适用于JavaScript和HTML。 Have a look at the code in such a TiddlyWiki file, there's code in there like this:
看一看这样的TiddlyWiki文件中的代码,里面有这样的代码:
// 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. 或者,根据需要支持的浏览器,可以研究HTML5的本地存储功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.