Hello,
I am trying to use the fopen function to read from an XML file on the client side.

What I have done is to make a flash movie (offline) open the URL:

http://somewhere.com/readfile.php?file=c:\temp\file.xml

The script will then open and read the xml file and do what it has to. When this script is run I get a 'unable to open file' error.

I realise that this can work perfectly if the XML file is located on the server but if anyone has any ideas on how to read from a file on the client side you will surely make my week!

Thanks!
Dee

    Hi,
    I'm sorry, but there is not way to read file from client side with php. And generally with http. You can't read a client file from server. You can only upload it.

    see you

      If the flash movie and the XML file are offline. Why dont you just use the XML object in FLASH, for example

      c = new XML();
      c.load("file.xml");

      c.onLoad = function()
      {
      //You cant put some code here to
      //for example tranform the XML
      //to an array
      }

      just make sure that the XML file and the SWF are on the same
      directory since we are just calling it c.load("file.xml") you can have
      relative or absolute paths in the load statement

      Hope this helps...

        Thanks for that , but using the XML object offline with Flash is not the problem, I am trying to use PHP to read the XML file and add its data to a MySQL database online.
        Any ideas?
        Thanks!
        Dee

          Upload the XML file to the server and have php add it to the mysql database... that is the easiest way.

          I think it is possible for flash to read the XML file on the client. Read the XML file in to flash and send the read XML file from flash to a PHP script that adds it to the MYSQL database... (i dont know if this is possible i have not tested this)

          Let me know if it works....

            I think the rigth way to do this is with SOAP.
            I know the SOAP is the XML over HTTP, and do exactly what you want. But how... I don't know. I'm just learning.

            see you

            (From http://www.w3schools.com I've recently getted this example:

            <html>
            <head>
            <script type="text/javascript">
            function search()
            {
            var parser=new ActiveXObject("microsoft.xmldom")
            parser.async="false"
            parser.load("tryxml_send.php?query=" + query.value)
            nodes = parser.documentElement.childNodes
            answer_text.innerHTML=nodes.item(0).text
            answer_xml.value=parser.xml
            }
            </script>
            </head>
            
            <body>
            <h2>Sending a query to the server
            and receiving the answer as XML:
            </h2>
            
            <p><b>Query: </b>
            <input type="text" name="query" value="How Old">
            <input type="button" value="Send to Server" onClick="search()">
            </p>
            
            <p><b>Answer from server is:</b>
            <span id="answer_text"></span>
            </p>
            
            <p><b>XML from server is:</b><br>
            <textarea id="answer_xml" cols="80" lines="10" rows="1">
            </p></body>
            </html>
            

            and with php I do this:

            <?
            /* for debug purpose, I'm writing the query... */
              $fil=fopen("temp.txt","wb");
              fwrite($fil,$query);
              fclose($fil);
              header("Content-Type: text/xml");
              echo "<answer><text>12 Years</text></answer>";
            ?>
            

            )

              The Flash developer informed me that the only way to send the read XML file to php is by passing it through the URL and the problem with that is that the amount of data that can be sent via a URL is limited.

                Write a Reply...