1

So this is probably a simple question, but for some reason, I'm having problems with it. I have no ideia why, but I suspect the fact that sending a xml with full "< something >" tags may cause the php to behave wrongly.

So all I need is to send (from a swf as3 client) a filename and a xml. The php will write a xml file with the required filename.

Everything should be okay with the php side, because I tried it using " $_GET " variables, but whenever I try using the flash client, It just doesent work, and the php log says that "the filename variable can't be empty". Whenever I try some static filename (not using GET or POST), it works.

Sooo... Can someone help me out with this one? Thanks.

EDIT: Code added.

var xmlURLReq:URLRequest = new URLRequest("www.url.com");
    var test:URLVariables = new URLVariables;
    test.filename = "01.xml";
    test.xmldata = xmltosave;
    xmlURLReq.data = teste;
    xmlURLReq.contentType = "text/xml";
    xmlURLReq.method = URLRequestMethod.POST;

    var xmlSendLoad:URLLoader = new URLLoader();
    xmlSendLoad.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
    xmlSendLoad.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    xmlSendLoad.load(xmlURLReq);

    var alertBox:alertBoxClass = new alertBoxClass();
    alertBox.x = 0;
    alertBox.y = 200;

    function onComplete(evt:Event):void 
    { 
        try 
        {
            var xmlResponse = new XML(evt.target.data);
            alertBox.alertText.text = "Inserção de dados bem sucedida!";
            addChild(alertBox);
            removeEventListener(Event.COMPLETE, onComplete);
            removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
            writeXML()
        }
    }

I also tried Object and LoadVars classes instead of URLVariables, no luck so far.

EDIT: Might as well add the php code as well.

<?php
    $filename = "http://url.com/".$_POST["filename"];
    $xml = $_POST["xmldata"];
    $file = fopen($filename , "wb");
    fwrite($file, $xml);
    fclose($file);
?>
4
  • Post some of your actionscript code. There is a limit to how much you can send with a GET, so you might want to try POST instead. Commented Oct 2, 2011 at 20:20
  • Edited with the code. I did use POST, I just used GET in the browser to check it. Commented Oct 2, 2011 at 20:31
  • My PHP is a bit rusty, but shouldn't that me $_POST when using the method POST? Or is $_GET the "universal" one? Commented Oct 2, 2011 at 21:13
  • Erm, lol sorry, that was wrong because I was making experiments. But changed to POST and still has the same problem. Just edited the code again with the POST, which is what I have now. Commented Oct 2, 2011 at 21:19

1 Answer 1

2

I see one possible problem in your code; You are setting the data to a URLVariables instance, but the contentType to "text/xml". It should be "application/x-www-form-urlencoded" when using URLVariables.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#contentType

Hope that solves it!

Sign up to request clarification or add additional context in comments.

8 Comments

Just tried that, but still not writing file. I always get a error log with a : fopen(URL) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: HTTP wrapper does not support writeable connections in URL/insertclient.php on line 8
Could you try logging the generated path ($filename) from the PHP file to see what it receives?
I'm a bit newby with php, can you tell me how to do that? I usually do "echo ($filename)", but since this is a comand coming from flash, I dont have a output windows. Is there a way to get it on the error_log?
I think error_log($filename) should do it. Haven't worked in PHP for years unfortunatley, so I'm a bit rusty. Might be easier to echo it and then print it from flash (evt.target.data iirc).
It actually gets the rights path. url.com/gestao/xml/01.xml (that's not the real xml, but I'm using an example of what should be created).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.