Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

File upload methods?

  • 17-09-2004 07:23PM
    #1
    Registered Users, Registered Users 2 Posts: 885 ✭✭✭


    Hi

    I am in the process of re-developing a website and am currently working on the admin section for updating the database. I have decided to use some new technologies for doing this as a kind of learning expierence for me. You can check out a prototype at.

    http://www.aor.ie/admin/prototype

    I am using a servlet to generate XML for the client.

    http://www.aor.ie/aor/servlet/XMLData
    to get a list of all property Id's.

    http://www.aor.ie/aor/servlet/XMLData?PropertyID=1070634500828
    to get all Info on an individual property.

    I am using a Microsoft.XMLDOM object to parse the XML and a javascript to enter the data into the fields. This seems to work well and gives the feel of a native application instead of a webpage.

    My problem is when somebody tries to add or update a record. I know I can use a Microsoft.XMLHTTP object to easily send the Text data to the server. But there is a picture as well that is selected using a File input control. Is there a script that allows me to access the data from the selected image without having to change the security settings which I will have no control over. I have found the following script on the net but requires some pretty dangerous changes to be made to the internet security settings. Even if the site is added to a trusted zone changes have to be made to the trusted sites settings.
    var ado_stream = new ActiveXObject("ADODB.Stream");
    
       // create XML document with default header and primary node
       var xml_dom = new ActiveXObject("MSXML2.DOMDocument");
       xml_dom.loadXML('<?xml version="1.0" ?> <root/>');
       // specify namespaces datatypes
       xml_dom.documentElement.setAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes");
    
       // create a new node and set binary content
       var l_node1 = xml_dom.createElement("file1");
       l_node1.dataType = "bin.base64";
       // open stream object and read source file
       ado_stream.Type = 1;  // 1=adTypeBinary 
       ado_stream.Open(); 
       ado_stream.LoadFromFile("c:\\tmp\\myfile.doc");
       // store file content into XML node
       l_node1.nodeTypedValue = ado_stream.Read(-1); // -1=adReadAll
       ado_stream.Close();
       xml_dom.documentElement.appendChild(l_node1);
    
       // we can create more XML nodes for multiple file upload
    
       // send XML documento to Web server
       var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       xmlhttp.open("POST","./file_recieve.asp",false);
       xmlhttp.send(xml_dom);
       // show server message in message-area
       div_message.innerHTML = xmlhttp.ResponseText;
    

    You would think that after a user has sellected a file using the File input control that you would be given rights to access that file.

    John.


Comments

  • Closed Accounts Posts: 2,525 ✭✭✭JustHalf


    I have to ask... why are you using an ActiveX-based DOM? Seems a bit silly, unless you're out to deny functionality to those who don't use IE.


  • Registered Users, Registered Users 2 Posts: 885 ✭✭✭clearz


    The intended users are guaranteed to be using Internet Explorer. But Im open to suggestions about cross browser methods of doing it.


  • Registered Users, Registered Users 2 Posts: 1,268 ✭✭✭hostyle


    clearz wrote:
    The intended users are guaranteed to be using Internet Explorer. But Im open to suggestions about cross browser methods of doing it.

    <form method="post" enctype="multipart/form-data">
    <input type="file" name="myfile" />
    <input type="submit" name="action" value="Upload />
    </form>
    

    ... unless you meant something else ...


  • Registered Users, Registered Users 2 Posts: 885 ✭✭✭clearz


    hostyle wrote:
    <form method="post" enctype="multipart/form-data">
    <input type="file"/>
    <input type="submit" name="action" value="Upload />
    </form>
    

    ... unless you meant something else ...


    Yes I did mean something else. As I said I am expiermenting with new ways of doing things. All I want to know is once a user selects a file with the normal file input control.<input type="file"/> Is their any way on the client side I can access that files data without changing the security settings or is the only way to send that file to the server by clicking on a submit button or using form.submit(); You would think that after a user has sellected a file using the File input control that you would be given rights to access that file.


Advertisement