Skip to main content
Participant
March 24, 2010
Question

How can I upload the XML file to the website using ColdFusion and read from it?

  • March 24, 2010
  • 3 replies
  • 1213 views

Hi,

I would like to use ColdFusion code to let user upload the selected XML file from their PC to the website.

And then let the user read the uploaded XML in simple XML tag.

Please guide me is there any special method CF allow us to do that? I can't seem to find it

Help would be really appreciated.

Thank you

    This topic has been closed for replies.

    3 replies

    clarattzkAuthor
    Participant
    March 26, 2010

    thk q for the help....i tested it out and it seems ok...but i haven't compiled with the rest of my codes yet...n hopefully there won't be any problem

    ilssac
    Inspiring
    March 24, 2010

    The only thing I would add to the previous repy, is that if you choose to just display the raw XML, I would strongly suggest that you escape it so that you don't expose yourself XSS.

    The htmleditformat() function makes that very easy.

    Fernis
    Inspiring
    March 24, 2010

    Creating a file upload form can be done with CFINPUT TYPE="FILE".

    Processing the uploaded file (saving it into disk) is handled with CFFILE ACTION="UPLOAD".

    XML is just text, so if you want to show the XML, it's just a matter of reading the uploaded file and displaying it as text.

    You can even create an XML document object of it, and use structure and array functions to access it. Or use CFDUMP to allow the user inspect the structure in more user friendly way, as in the code example below:


    <cfif NOT isdefined("submit")>
        <cfform name="form1" enctype="multipart/form-data">
        <cfinput type="file" name="myfile">
        <cfinput type="submit" name="submit" value="Upload">
        <cfinput type="hidden" name="requestTimeout" value="240">
        </cfform>
    <cfelse>
        <cffile action="upload" filefield="myfile" destination="#expandpath('./')#" nameconflict="overwrite" accept="text/xml,application/xml">
        <cfset myXMLDocument=XmlParse("#expandpath('./')##CFFILE.serverfile#")>
        <cfdump var="#myXMLDOcument#">
    </cfif>

    --

    - Fernis - fernis.net - ColdFusion Developer For Hire