使用PHP / JS用上传的文件动态填充网页 [英] Dynamically populating webpage with uploaded file using PHP/JS

查看:78
本文介绍了使用PHP / JS用上传的文件动态填充网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是修改页面,以便它接受上载的文件并解析该文件的内容以以特定格式显示它。

I have been tasked with modifying a page so that it accepts an uploaded file and parses the contents of that file to display it in a particular format.

解析文件的代码-但当前它读取服务器上的静态文件并将其读取为字符串。相反,我希望文件的内容在上传后填充字符串。

I have code that parses the file - but currently it reads a static file on the server and reads it as a string. Instead I want the contents of the file to populate the string after upload.

使用PHP / JS完成此操作的最佳方法是什么?我宁愿完全不使用PHP,但是如果需要的话也可以。

What's the best way to accomplish this using PHP/JS. I would prefer not to use PHP at all if possible, but it's fine if I have to.

也欢迎使用其他选项。

谢谢

编辑:

感谢-我将在不久之后发布代码我还没有做出任何更改。

Thanks - I will post the code shortly as I'm yet making some changes to it.

这可能是一个愚蠢的问题,但是我对AJAX并不熟悉。

This might be a stupid question, but I'm not familiar with AJAX.

是否必须将文件上传到任何位置,或者可以将其临时存储在变量中。

Does the file have to be uploaded to any location, or can it be temporarily housed in a variable.

我需要使用的文件是

http://distributome.avinashc.com/howardL/scripts/distributome.js

尤其是行xmlDoc = xmlhttp.responseXML;

In particular the lines xmlDoc = xmlhttp.responseXML;

我正在使用操作打开文件 Distributome.xml

I am opening the file "Distributome.xml" using the operation

xmlhttp.open( GET, Distributome.xml,false);

xmlhttp.open("GET","Distributome.xml",false);

我想使用一个XML文件(或两个)来填充它)用户上传。

Instead I want to populate it using an XML file (or two) that the user uploads.

作为任务的另一部分;我需要使用两个文件,以便它们包含不同的数据。因此,现在我只添加两个文件-在我已评论的行中。

As another part of the task; I need to use two files so that they contain different data; so for now I am just appending the two files - in the lines that I have commented.

编辑:

   {        
   /*
   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);
   }

编辑:

我没有将文件上传到服务器;取而代之的是,我只希望用户在本地上载时解析内容。

I am not uploading the file to the server; instead I just want the content to be parsed when the user uploads - locally.

推荐答案

您可以从这里开始:
http://www.html5rocks.com/zh-CN/tutorials/file/dndfiles /

在此处找到它。

这篇关于使用PHP / JS用上传的文件动态填充网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆