我的任務是修改頁面,以便它接受上傳的文件並解析該文件的內容以特定格式顯示它。使用PHP/JS動態填充上傳文件的網頁
我有解析文件的代碼 - 但它目前讀取服務器上的靜態文件並將其作爲字符串讀取。相反,我希望文件的內容在上傳後填充字符串。
使用PHP/JS完成此操作的最佳方法是什麼?如果可能的話,我寧願不使用PHP,但如果必須的話,這很好。
其他選項也歡迎。
感謝
編輯:
謝謝 - 我會後的代碼作爲不久,我又做了一些更改。
這可能是一個愚蠢的問題,但我不熟悉AJAX。
該文件是否必須上傳到任何位置,或者它是否可以臨時安置在變量中。
文件我需要使用是
http://distributome.avinashc.com/howardL/scripts/distributome.js
特別地,線xmlDoc中= xmlhttp.responseXML;
我使用的操作
xmlhttp.open打開文件 「Distributome.xml」( 「GET」, 「Distributome.xml」,假);
相反,我想使用用戶上傳的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請求獲取上傳的文件,您就可以繼續使用現有的邏輯。 :) – jmort253
另外,如果您發佈了您的代碼,我們可以提供更好的幫助。只需使用您的問題下的** edit **鏈接即可添加更多詳細信息。 – jmort253