Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: as3 php xml
Forum PHP.pl > Forum > PHP
awariat
mam wspaniały kod ktory przesyła mi dane xml do php i zapisuje do pliku xml

  1. <?php
  2. $fh = fopen("themes/test/test.xml", 'w') or die("can't open file");
  3. $xml ='<'.'?xml version="1.0" encoding="utf-8"?'.'>'. "\r\n" .$HTTP_RAW_POST_DATA ;
  4. fwrite($fh, $xml);
  5. fclose($fh);
  6. $odp="wyslano dane \r\n";
  7. echo($odp);
  8. ?>


i kod as3

  1. function SendToURLExample(event:MouseEvent):void {
  2. trace(xml)
  3.  
  4. var xmlResponse:XML;
  5. var xmlURLReq:URLRequest=new URLRequest("saveTheme.php");
  6. xmlURLReq.data=xml;// tu znajduje sie moj xml
  7. xmlURLReq.contentType="text/xml";
  8. xmlURLReq.method=URLRequestMethod.POST;
  9. var xmlSendLoad:URLLoader = new URLLoader();
  10. xmlSendLoad.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
  11. xmlSendLoad.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
  12. xmlSendLoad.load(xmlURLReq);
  13. function onComplete(evt:Event):void {
  14. ...
  15. }
  16. function onIOError(evt:IOErrorEvent):void {
  17. ...
  18. }
  19. }
  20.  
  21. save_project.addEventListener(MouseEvent.MOUSE_DOWN, SendToURLExample);



jednak ten xml we flaszu "zajmuje" całe xmlURLReq.data a potrzebuje jeszcze wysłac nazwe katalogu do php

probowałem tak jak sie wysyła normalne zmienne naprzyklad stringi

  1. function SendToURLExample(event:MouseEvent):void {
  2. var url:String="saveTheme.php";
  3. var variables:URLVariables = new URLVariables();
  4.  
  5. variables.kat="test"
  6. variables.xml=xml.toString();
  7.  
  8.  
  9.  
  10. var request:URLRequest=new URLRequest(url);
  11. request.data=variables;
  12. request.method=URLRequestMethod.POST;
  13. trace(variables);
  14. try {
  15. sendToURL(request);
  16. } catch (e:Error) {
  17. // handle error here
  18. }
  19. }


i php

  1. <?php
  2. extract ( $_POST );
  3. $flaxml = $_POST['xml'];
  4. $flakat = $_POST['kat'];
  5.  
  6. $fh = fopen("themes/".$flakat."/".$flakat.".xml", 'w') or die("can't open file");
  7. $xml ='<'.'?xml version="1.0" encoding="utf-8"?'.'>'. "\r\n" .$flaxml ;
  8. fwrite($fh, $xml);
  9. fclose($fh);
  10. $odp="wyslano dane \r\n".kat;
  11. echo($odp);
  12. echo($fh);
  13. echo($xml);
  14. ?>


jednak czy robie
variables.xml=xml.toString(); czy variables.xml=xml.toXMLString(); czy tylko variables.xml=xml

wynikiem jest zapis do xml ale to juz nie jest xml tylko xml zepsuty

<site name="site\">
<bg name=\"LAY1\" type=\"layout\">
<bg name=\"kolor0\" type=\"buildin\" source=\"AllFacesCOLOR\" width=\"stageWidth\" alpha=\"1\" height=\"stageHeight\" parameters=\"0xbfb297\"/>
<bg name=\"kolor1\" type=\"buildin\" so

jak zamienic $flaxml = $_POST['xml']; na xml spowrotem i zapisac by było ok

ok moge dołaczyc header do tego przesyłu

URLRequestHeader


jak go odczytac w php pozniej


  1. var xmlURLReq:URLRequest=new URLRequest("saveTheme.php");
  2. var header:URLRequestHeader = new URLRequestHeader("plik", "test");/*************************/
  3. xmlURLReq.data=xml;
  4. xmlURLReq.contentType="text/xml";
  5. xmlURLReq.method=URLRequestMethod.POST;
  6. request.requestHeaders.push(header);/*************************/


mogłbym w tym headerze przesłac nazwe katalogu i tylko jak go odczytac w php
i czy nie popierniczy kodu tez
R4D3K
  1. <site name="site\">
  2. <bg name=\"LAY1\" type=\"layout\">
  3. <bg name=\"kolor0\" type=\"buildin\" source=\"AllFacesCOLOR\" width=\"stageWidth\" alpha=\"1\" height=\"stageHeight\" parameters=\"0xbfb297\"/>
  4. <bg name=\"kolor1\" type=\"buildin\" so

Wydaje mi się, że tew apostrofy masz z powodu włączonego mechanizmu magic_quotes, albo je wyłącz ( co jest niebezpiecznie i pamietaj o sql injection) albo użyj stripslashes() na $_POST
awariat
$xml ='<'.'?xml version="1.0" encoding="utf-8"?'.'>'. "\r\n" .stripslashes($flaxml) ;

dzieki bardzo
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.