【发布时间】:2012-05-21 07:22:55
【问题描述】:
我的任务是修改一个页面,使其接受上传的文件并解析该文件的内容,以特定格式显示它。
我有解析文件的代码 - 但目前它读取服务器上的静态文件并将其作为字符串读取。相反,我希望文件的内容在上传后填充字符串。
使用 PHP/JS 完成此任务的最佳方法是什么。如果可能的话,我宁愿完全不使用 PHP,但如果必须的话也没关系。
也欢迎其他选项。
谢谢
编辑:
谢谢 - 我会尽快发布代码,因为我还在对其进行一些更改。
这可能是一个愚蠢的问题,但我对 AJAX 并不熟悉。
文件是否必须上传到任何位置,或者可以临时存放在变量中。
我需要使用的文件是
http://distributome.avinashc.com/howardL/scripts/distributome.js
特别是 xmlDoc = xmlhttp.responseXML;
我正在使用该操作打开文件“Distributome.xml”
xmlhttp.open("GET","Distributome.xml",false);
相反,我想使用用户上传的一个(或两个)XML 文件来填充它。
作为任务的另一部分;我需要使用两个文件,以便它们包含不同的数据;所以现在我只是在我评论的行中附加两个文件。
编辑:
{
/*
Split into distributions and relations - but append them
xmlhttp.open("GET","Distributome.xml",false);
xmlhttp.send();
if (!xmlhttp.responseXML.documentElement && xmlhttp.responseStream)
xmlhttp.responseXML.load(xmlhttp.responseStream);
xmlDoc = xmlhttp.responseXML;
xmlhttp.open("GET","Distributome-references.xml",false);
xmlhttp.send();
if (!xmlhttp.responseXML.documentElement && xmlhttp.responseStream)
xmlhttp.responseXML.load(xmlhttp.responseStream);
xmlDoc = xmlDoc+xmlhttp.responseXML;
*/
getURLParameters();
/*** Read in and parse the Distributome.xml DB ***/
var xmlhttp=createAjaxRequest();
xmlhttp.open("GET","Distributome.xml",false);
xmlhttp.send();
if (!xmlhttp.responseXML.documentElement && xmlhttp.responseStream)
xmlhttp.responseXML.load(xmlhttp.responseStream);
xmlDoc = xmlhttp.responseXML;
try{
DistributomeXML_Objects=xmlDoc.documentElement.childNodes;
}catch(error){
DistributomeXML_Objects=xmlDoc.childNodes;
}
traverseXML(false, null, DistributomeXML_Objects, distributome.nodes, distributome.edges, distributome.references, distributomeNodes, referenceNodes);
xmlhttp=createAjaxRequest();
xmlhttp.open("GET","Distributome.xml.pref",false);
xmlhttp.send();
if (!xmlhttp.responseXML.documentElement && xmlhttp.responseStream)
xmlhttp.responseXML.load(xmlhttp.responseStream);
var ontologyOrder = xmlhttp.responseXML;
getOntologyOrderArray(ontologyOrder);
}
编辑:
我没有将文件上传到服务器;相反,我只想在用户上传时解析内容 - 本地。
【问题讨论】:
-
为什么文件上传后不能发出 AJAX 请求来获取文件的内容?
-
特别是如果您已经从文件系统中读取字符串!你我的朋友已经做好了。只要您可以发出 AJAX 请求来获取上传的文件,就可以继续使用现有的逻辑。 :)
-
顺便说一句,如果您发布您拥有的代码,我们可以提供更好的帮助。只需使用问题下方的编辑链接添加更多详细信息。
-
谢谢 - 我会尽快发布代码,因为我还在对其进行一些更改。这可能是一个愚蠢的问题,但我不熟悉 AJAX。文件是否必须上传到任何位置,或者可以临时存放在变量中。我需要使用的文件是distributome.avinashc.com/howardL/scripts/distributome.js 特别是 xmlDoc = xmlhttp.responseXML;我正在使用操作 xmlhttp.open("GET","Distributome.xml",false); 打开文件“Distributome.xml”。相反,我想使用用户上传的一个(或两个)XML 文件来填充它。
标签: php javascript dynamic upload