A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Appending XML with Flash & PHP

  1. #1
    Senior Member
    Join Date
    Aug 2007
    Posts
    291

    Appending XML with Flash & PHP

    Hey all,

    I'm doing a church website and I'm trying to create an app where someone from the church can upload a preacher's sermon and it will be added to the mp3 player that I created (which is driven by an XML file). So, after doing some research I realized that I have to do this in PHP, but I can't get it to work.

    Everything on the Flash side appears to be working properly and I'm not getting any errors, but there is no mp3 file uploaded to my server and the XML file is not updated. Can you guys help me? FYI, I'm using AS 3.0.

    Here's my PHP:
    PHP Code:
    <?php
    /* 
            Script Written By: Adam Khoury @ www.developphp.com 
            Adapted by Justin Summerlin
    */
    // Set local PHP vars from the POST vars sent from flash
    $todayDate $_POST['todayDate'];
    $Speaker $_POST['Speaker'];
    $Date $_POST['sermonDate'];
    $Title $_POST['Title'];
    $filename $_FILES['Filedata']['name'];    
    $filetmpname $_FILES['Filedata']['tmp_name'];    
    $fileType $_FILES["Filedata"]["type"];
    $fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 1000);


    // Place file on server, into the sermons folder
    move_uploaded_file($_FILES['Filedata']['tmp_name'], "sermons/sermons/".$filename);

    // This section edits your log file, if you don't need a text log file just delete these lines
    $myFile "logFile.txt";
    $fh fopen($myFile'a') or die("can't open file");
    $stringData "\n\ntodayDate: $todayDate  \n Name: $Name \n Email: $Email \n ssid: $ssid \n FileName: $filename \n TmpName: $filetmpname \n Type: $fileType \n Size: $fileSizeMB MegaBytes";
    fwrite($fh$stringData);
    fclose($fh);
    // End log file edit

    //Appending to the current XML file

    //Creating a new DomDocument
    $xdoc = new DomDocument;

    //Loading in the current XML file
    $xdoc->Load('http://www.wagramchurchofgod.com/sermons/xmlTest.xml');

    //getting the ROOT element (in this case, it's "songs")
    $songs $xdoc->getElementsByTagName('songs')->item(0);

    //creating a new "song" element underneat the root
    $newElement $xdoc ->createElement('song');

    //adding the URL attribute to the new song element
    $url $xdoc->createAttribute("url");
    $newElement->appendChild($url);
    $urlValue $dom->createTextNode("sermons/".$filename);
    $url->appendChild($urlValue);

    //adding the PREACHER attribute to the new song element
    $preacher $xdoc->createAttribute("preacher");
    $newElement->appendChild($preacher);
    $preacherValue $dom->createTextNode($Speaker);
    $preacher->appendChild($preacherValue);

    //adding the DATE attribute to the new song element
    $myDate $xdoc->createAttribute("date");
    $newElement->appendChild($myDate);
    $myDateValue $dom->createTextNode($Date);
    $myDate->appendChild($myDateValue);

    //adding the TITLE attribute to the new song element
    $myTitle $xdoc->createAttribute("title");
    $newElement->appendChild($myTitle);
    $myTitleValue $dom->createTextNode($Title);
    $myTitle->appendChild($myTitleValue);

    //adding the new element, WITH ATTRIBUTES, to the <SONGS> element in the XML file
    $songs -> appendChild($newElement);

    //Saving the XML file and printing the results to the $test variable
    $test $xdoc->save("http://www.wagramchurchofgod.com/sermons/xmlTest.xml");
    echo 
    "<B>Data Appended<B>";
    echo 
    $test;

    ?>
    And here's my Actionscript (if you need it):
    PHP Code:
    stop();

    btnSermons.addEventListener(MouseEvent.CLICKshowSermons);

    function 
    showSermons(e:MouseEvent):void
    {
        
    btnEvents.addEventListener(MouseEvent.CLICKshowEvents);
        
    btnSermons.removeEventListener(MouseEvent.CLICKshowSermons);
        
        
    Tweener.addTween(btnEvents, {x:639time:1transition:"easeOutQuint"})
        
    Tweener.addTween(mcSermonsPage, {x:328time:1transition:"easeOutQuint"})
    }

    function 
    showEvents(e:MouseEvent):void
    {
        
    btnSermons.addEventListener(MouseEvent.CLICKshowSermons);
        
    btnEvents.removeEventListener(MouseEvent.CLICKshowEvents);
        
        
    Tweener.addTween(btnEvents, {x:89time:1transition:"easeOutQuint"})
        
    Tweener.addTween(mcSermonsPage, {x:-222time:1transition:"easeOutQuint"})
    }











    /*------------------------------------------------------------------------------------*/
    /*
    Script Written By: Adam Khoury @ www.developphp.com
    adapted by Justin Summerlin
    */
    // First thing is to set the flashing upload message clip to invisible
    //uploadMsg.visible = false;


    // Set the URL for the PHP uploader script
    var url:URLRequest = new URLRequest("http://www.wagramchurchofgod.com/Scripts/uploader_script.php");

    // Assign the image types Filter
    var audioTypes:FileFilter = new FileFilter("Audio (*.mp3)""*.mp3");

    // Set the FileReference name
    var fileRef:FileReference = new FileReference();
    var 
    toggler:Number 0;

    // Add event listeners for its various fileRef functions below
    fileRef.addEventListener(Event.SELECTsyncVariables);
    fileRef.addEventListener(Event.COMPLETEcompleteHandler);
    fileRef.addEventListener(ProgressEvent.PROGRESSprogressHandler);

    //event listener for error text holder
    mcSermonsPage.mcError.addEventListener(MouseEvent.CLICKgrow);

    function 
    grow(e:MouseEvent):void
    {
        if(
    toggler == 0)
        {
            
    Tweener.addTween(mcSermonsPage.mcError, {x:20.1y:-6.4scaleX:1scaleY:1time:1transition:"easeOutQuint"});
            
    toggler++;
        }
        else
        {
            
    Tweener.addTween(mcSermonsPage.mcError, {x:250.2y:-116.4scaleX:.1scaleY:.1time:1transition:"easeOutQuint"});
            
    toggler 0;
        }
    }

    // Add event listeners for your 2 buttons
    mcSermonsPage.btnBrowse.addEventListener(MouseEvent.CLICKbrowseBox);
    mcSermonsPage.btnBrowse.buttonMode true;
    mcSermonsPage.btnDone.addEventListener(MouseEvent.CLICKuploadVars);
    mcSermonsPage.btnDone.buttonMode true;

    // Function that fires off when the user presses "browse for a file"
    function browseBox(e:MouseEvent):void 
    {
        
    fileRef.browse([audioTypes]);
    }
    // Function that fires off when the user presses the "upload it now" btn
    function uploadVars(e:MouseEvent):void 
    {
        
    mcSermonsPage.mcBlocker.visible false;
        
    //uploadMsg.visible = true;
        
    fileRef.upload(url);
        
    mcSermonsPage.btnDone.visible false;
    }
    // Function that fires off when File is selected from PC and Browse dialogue box closes
    function syncVariables(e:Event):void 
    {
        
    mcSermonsPage.txtFilename.text "" fileRef.name;
        
        
    mcSermonsPage.btnDone.visible true;
        
    mcSermonsPage.mcProgress.width 1;
        var 
    variables:URLVariables = new URLVariables();
        
    variables.todayDate = new Date();
        
    variables.Title mcSermonsPage.txtTitle.text// Title of the sermon
        
    variables.Speaker mcSermonsPage.txtSpeaker.text// the person who preached the sermon
        
    variables.sermonDate mcSermonsPage.txtDate.text// date of sermon
        
    url.method URLRequestMethod.POST;
        
    url.data variables;
    }
    // Function that fires off when upload is complete
    function completeHandler(e:Event):void 
    {
        
    //uploadMsg.visible = false;
        
    mcSermonsPage.mcBlocker.visible true;
        
    mcSermonsPage.txtStatus.text "Your file has been uploaded successfully.";
        
    mcSermonsPage.txtFilename.text "";
    }
    // Function that fires off when the upload progress begins
    function progressHandler(e:ProgressEvent):void 
    {
        
    // we want our progress bar to be 200 pixels wide when done growing so we use 200*
        // Set any width using that number, and the bar will be limited to that when done growing
        
    mcSermonsPage.mcProgress.width Math.ceil(200*(e.bytesLoaded/e.bytesTotal));
        
    mcSermonsPage.txtPercent.text String(Math.ceil(100*(e.bytesLoaded/e.bytesTotal))) + "%";


  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    you can probably load xml from a http address, but certainly not save to it.
    You should load and save from a file, and that would most likely be "sermons/xmlTest.xml"

    Is your sermons/sermons folder writable for php? (permissions should be set to 777 on most unix servers for that)
    Do you receive the output from echo statement?

    Musicman

  3. #3
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    This church has their website hosted on Yahoo. Any ideas how I would go about finding out the permissions on a folder through Yahoo hosting?

    And, no. Nothing is printed on the screen. The page doesn't work. I even inserted some HTML headers and such in there so I could give the page a title and the title doesn't even show up on the top of the browser. When I comment out all the PHP, it works... of course.

  4. #4
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    So, I'm trying to just use a workaround and build a string (of XML) and then just append that onto a file using fopen and fwrite. Here's my code that works and after it, I'll post my code that doesn't work:

    PHP Code:
    <?php

    $Speaker 
    "your mother";
    $Date "07/18/2005";
    $Title "testing";
    $filename "fudgelick.mp3";

    //this part works
    $test 'test1"'.$Speaker.'"test2';
    $test1 $test.'="'.$Date.'" blah=';
    $test2 $test1.'="'.$Title.'" blah2=';

    echo 
    $Speaker."<br>";
    echo 
    "$Date<br>";
    echo 
    "$Title<br>";
    echo 
    "$filename<br>";

    //this part prints exactly what you'd think
    echo "$test<br>";
    echo 
    "$test1<br>";
    echo 
    "$test2<br>";

    echo 
    "<B>Data Appended<B>";

    ?>
    Output from that PHP:

    your mother
    07/18/2005
    testing
    fudgelick.mp3
    test1"your mother"test2
    test1"your mother"test2="07/18/2005" blah=
    test1"your mother"test2="07/18/2005" blah=="testing" blah2=
    Data Appended

    --------END OUTPUT--------


    So, that works, but trying to build an XML string doesn't.

    PHP Code:
    <?php

    $Speaker 
    "your mother";
    $Date "07/18/2005";
    $Title "testing";
    $filename "fudgelick.mp3";

    $myString '<song url="'.$filename.'" preacher="'.$Speaker.'" date="'.$Date.'" title="'.$Title.'"/>';
    $build1 '<song url="'.$filename.'" preacher="';
    $build2 .= $build1.$Speaker.'" date="';
    $build3 .= $build2.$Date.'" title="';
    $build4 .= $build3.$Title.'"/>';

    echo 
    $Speaker."<br>";
    echo 
    "$Date<br>";
    echo 
    "$Title<br>";
    echo 
    "$filename<br>";

    echo 
    "$build1<br>";
    echo 
    "$build2<br>";
    echo 
    "$build3<br>";
    echo 
    "$build4<br>";

    echo 
    "$myString<br>";

    echo 
    "<B>Data Appended<B>";

    ?>

    Output from that PHP (notice the space after fudgelick.mp3):

    your mother
    07/18/2005
    testing
    fudgelick.mp3


    Data Appended

    ------END OUTPUT------

    Any ideas?

  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    how about -
    PHP Code:
    <?php
    $Speaker 
    "your mother";
    $Date "07/18/2005";
    $Title "testing";
    $filename "fudgelick.mp3";

    $doc new_xmldoc("1.0");
    $root $doc->add_root('sermon');

    $member $root->new_child('song','');

    $member->new_child('url',$filename);
    $member->new_child('preacher',$Speaker);
    $member->new_child('date',$Date);
    $member->new_child('title',$Title);

    $fp = @fopen('sermon.xml','w');
    if(!
    $fp) {
        die(
    'Error');
    }
    fwrite($fp,$doc->dumpmem());
    fclose($fp);
    ?>
    sermon.xml will show -
    PHP Code:
      <?xml version="1.0" ?> 
     <sermon>
     <song>
      <url>fudgelick.mp3</url> 
      <preacher>your mother</preacher> 
      <date>07/18/2005</date> 
      <title>testing</title> 
      </song>
      </sermon>

  6. #6
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    That worked. However, is there a way to make this script edit an existing XML document? The reason I ask, is that my mp3 player is already using an XML document to get it's data, and it will likely have more than one item on it at a time. So, I don't want to create a new XML document every time someone adds a sermon to the website. Know what I mean?

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    you could use this method where test.xml is simply overwritten with new data -

    http://www.jackleaman.co.uk/test/wri...hange_xml.html

  8. #8
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    Okay, so let me see if I get this....

    You open the XML file with Flash, and then you add something to the end of it IN FLASH, and then send the entire thing back to PHP at which point it overwrites the old XML file?

    That's just crazy enough to work...

    Seriously though, I'm going to give this a try and I'll let you know how it turns out. Thanks for your help.

    EDIT:
    This is in AS2. You think it would be difficult to port to AS3? I think I'm going to give that a whirl too... maybe...
    Last edited by Taidaishar; 09-25-2009 at 11:41 AM.

  9. #9
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    Okay. Here's what I have so far, and I have everything working but the variable passing between the PHP and the Flash. What I mean, is that the songs2.xml file is showing only "null" as it's text. I had to adapt the PHP script for my own purposes, but maybe you could tell me what's wrong with it. I'll try to highlight the parts of the actionscript in question.


    here's the PHP as I now have it. So far, the upload file is working correctly. It puts the file in the proper directory with a proper name.
    PHP Code:
    <?php
    $mybody 
    urldecode($_POST["body"]);
    if(!
    $mybody){
    print 
    "&returnMe=Server Error!";
    exit;
    }else{

    $filename $_FILES['Filedata']['name'];    
    $filetmpname $_FILES['Filedata']['tmp_name'];    
    $fileType $_FILES["Filedata"]["type"];
    $fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 1000);

    move_uploaded_file($_FILES['Filedata']['tmp_name'], "/sermons/sermons/".$filename);

    $filefopen("/sermons/songs2.xml""w");
    fwrite($file"$mybody");
    fclose($file);
    print 
    "&returnMe=File saved&file=".$body."&";
    }
    ?>

    Here's the Actionscript (remember, this is 3.0)
    PHP Code:
    stop();

    btnSermons.addEventListener(MouseEvent.CLICKshowSermons);

    function 
    showSermons(e:MouseEvent):void
    {
        
    btnEvents.addEventListener(MouseEvent.CLICKshowEvents);
        
    btnSermons.removeEventListener(MouseEvent.CLICKshowSermons);
        
        
    Tweener.addTween(btnEvents, {x:639time:1transition:"easeOutQuint"})
        
    Tweener.addTween(mcSermonsPage, {x:328time:1transition:"easeOutQuint"})
    }

    function 
    showEvents(e:MouseEvent):void
    {
        
    btnSermons.addEventListener(MouseEvent.CLICKshowSermons);
        
    btnEvents.removeEventListener(MouseEvent.CLICKshowEvents);
        
        
    Tweener.addTween(btnEvents, {x:89time:1transition:"easeOutQuint"})
        
    Tweener.addTween(mcSermonsPage, {x:-222time:1transition:"easeOutQuint"})
    }











    /*------------------------------------------------------------------------------------*/
    /*
    Script Written By: Adam Khoury @ www.developphp.com
    adapted by Justin Summerlin
    */
    // First thing is to set the flashing upload message clip to invisible
    //uploadMsg.visible = false;






    // Set the URL for the PHP uploader script
    var url:URLRequest = new URLRequest("writeit2.php");

    // Assign the image types Filter
    var audioTypes:FileFilter = new FileFilter("Audio (*.mp3)""*.mp3");

    // Set the FileReference name
    var fileRef:FileReference = new FileReference();
    var 
    toggler:Number 0;

    // Add event listeners for its various fileRef functions below
    fileRef.addEventListener(Event.SELECTsyncVariables);
    fileRef.addEventListener(Event.COMPLETEcompleteHandler);
    fileRef.addEventListener(ProgressEvent.PROGRESSprogressHandler);

    //event listener for error text holder
    mcSermonsPage.mcError.addEventListener(MouseEvent.CLICKgrow);

    function 
    grow(e:MouseEvent):void
    {
        if(
    toggler == 0)
        {
            
    Tweener.addTween(mcSermonsPage.mcError, {x:20.1y:-6.4scaleX:1scaleY:1time:1transition:"easeOutQuint"});
            
    toggler++;
        }
        else
        {
            
    Tweener.addTween(mcSermonsPage.mcError, {x:250.2y:-116.4scaleX:.1scaleY:.1time:1transition:"easeOutQuint"});
            
    toggler 0;
        }
    }

    // Add event listeners for your 2 buttons
    mcSermonsPage.btnBrowse.addEventListener(MouseEvent.CLICKbrowseBox);
    mcSermonsPage.btnBrowse.buttonMode true;
    //mcSermonsPage.btnDone.addEventListener(MouseEvent.CLICK, readXML);
    mcSermonsPage.btnDone.addEventListener(MouseEvent.CLICKuploadVars);
    mcSermonsPage.btnDone.buttonMode true;

    // Function that fires off when the user presses "browse for a file"
    function browseBox(e:MouseEvent):void 
    {
        
    fileRef.browse([audioTypes]);
    }
    // Function that fires off when the user presses the "upload it now" btn
    function uploadVars(e:MouseEvent):void 
    {
        
    mcSermonsPage.mcBlocker.visible false;
        
    //uploadMsg.visible = true;
        
    fileRef.upload(url);
        
    mcSermonsPage.btnDone.visible false;
        
    readXML();
    }


    var 
    path:String "/sermons/";
    var 
    myXML:XML;

    //reads in the current XML document in order to add to it

    //function readXML(e:Event):void
    function readXML():void
    {
        
    //xmlText.text = "reading xml file";
        
    var vers:* = new Date().getTime();
        
        var 
    myLoader:URLLoader = new URLLoader();
        
        
    //myLoader.load(new URLRequest("songs2.xml"));
        
    myLoader.load(new URLRequest(path+"songs2.xml"));
        
    myLoader.addEventListener(Event.COMPLETExmlLoaded);
        
    };


    function 
    xmlLoaded(e:Event):void
    {
        
    trace("1");
        
    myXML = new XML(e.target.data);
        var list:
    XMLList = new XMLList(myXML);
        
        
    trace("1:" myXML);
        
        
    trace("2");
        
        var 
    node:XMLNode = new XMLNode(1"song")
        
        
    trace("3");
        var 
    urlNode:XMLNode = new XMLNode(1"url");
        var 
    urlText:XMLNode = new XMLNode(3"sermons/"+mcSermonsPage.txtFilename.text)
        
    urlNode.appendChild(urlText);
        
    node.appendChild(urlNode)
        
    trace("4");
        var 
    preacherNode:XMLNode = new XMLNode(1"preacher");
        var 
    preacherText:XMLNode = new XMLNode(3mcSermonsPage.txtSpeaker.text)
        
    preacherNode.appendChild(preacherText);
        
    node.appendChild(preacherNode)
        
    trace("5");
        var 
    dateNode:XMLNode = new XMLNode(1"date");
        var 
    dateText:XMLNode = new XMLNode(3mcSermonsPage.txtDate.text)
        
    dateNode.appendChild(dateText);
        
    node.appendChild(dateNode)
        
    trace("6");
        var 
    titleNode:XMLNode = new XMLNode(1"title");
        var 
    titleText:XMLNode = new XMLNode(3mcSermonsPage.txtTitle.text)
        
    titleNode.appendChild(titleText);
        
    node.appendChild(titleNode)
        
    trace("7");
        
        list.
    appendChild(node);
        
        
    trace("8");
        
    trace("2:" myXML);
        
    trace("3:" + list);
        
        
    //ts = new Date();
        //entityToTxt(unescape(this));
    };


    /*//builds the entire XML document that will be sent to the PHP file
    function buildXML()
    {
        send_lv = new LoadVars();
        send_lv.body = escape(xmlText.text);
        trace(xmlText.text)
        trace(escape(xmlText.text)
        send_lv.sendAndLoad(path+"writeit2.php", send_lv, "POST");
        send_lv.onLoad = function()
        {
            tracer.text += this.returnMe;
            entityToTxt(unescape(this.file));
            tracer.text += newline+"// "+ts+newline+
            "// Saved as test.xml"+newline;
        };
    };*/

    //**********************************************************//
    //**********************************************************//
    //************ FUNCTION THAT CREATES THE VARIABLES **************//
    //**********************************************************//



    // Function that fires off when File is selected from PC and Browse dialogue box closes
    function syncVariables(e:Event):void 
    {
        
    mcSermonsPage.txtFilename.text "" fileRef.name;
        
        
    mcSermonsPage.btnDone.visible true;
        
    mcSermonsPage.mcProgress.width 1;
        var 
    variables:URLVariables = new URLVariables();
        
    variables.body myXML;
        
    url.method URLRequestMethod.POST;
        
    url.data variables;
    }





    // Function that fires off when upload is complete
    function completeHandler(e:Event):void 
    {
        
    //uploadMsg.visible = false;
        
    mcSermonsPage.mcBlocker.visible true;
        
    mcSermonsPage.txtStatus.text "Your file was uploaded successfully!";
        
    mcSermonsPage.txtFilename.text "";
    }





    // Function that fires off when the upload progress begins
    function progressHandler(e:ProgressEvent):void 
    {
        
    // we want our progress bar to be 200 pixels wide when done growing so we use 200*
        // Set any width using that number, and the bar will be limited to that when done growing
        
    mcSermonsPage.mcProgress.width Math.ceil(200*(e.bytesLoaded/e.bytesTotal));
        
    mcSermonsPage.txtPercent.text String(Math.ceil(100*(e.bytesLoaded/e.bytesTotal))) + "%";
    }


    /*****************************************************************************************/
    /*****************************************************************************************/
    /*************************             I'm not using anything below this.... mainly because I don't know how it works or what it's for           ***********************/
    /*****************************************************************************************/
    /*****************************************************************************************/
    /*****************************************************************************************/


    /*//convert entities to plain text
    arr1 = new Array();
    arr2 = new Array();
    arr1[0]="&amp;";     arr2[0]="&";
    arr1[1]="&quot;";    arr2[1]="\"";
    arr1[2]="&apos;";    arr2[2]="\'";
    arr1[3]="&aacute";   arr2[3]="Ã*";
    arr1[4]="&acirc;";   arr2[4]="â";
    arr1[5]="&aelig;";   arr2[5]="æ";
    arr1[6]="&agrave;";  arr2[6]="Ã*";
    arr1[7]="&aring;";   arr2[7]="Ã¥";
    arr1[8]="&atilde;";  arr2[8]="ã";
    arr1[9]="&auml";     arr2[9]="ä";
    arr1[10]="&ccedil";  arr2[10]="ç";
    arr1[11]="&eacute;"; arr2[11]="é";
    arr1[12]="&ecirc;";  arr2[12]="ê";
    arr1[13]="&egrave;"; arr2[13]="è";
    arr1[14]="&euml;";   arr2[14]="ë";
    arr1[15]="&gt;";     arr2[15]=">";
    arr1[16]="&iacute;"; arr2[16]="Ã*";
    arr1[17]="&icirc;";  arr2[17]="î";
    arr1[18]="&igrave;"; arr2[18]="ì";
    arr1[19]="&iuml;";   arr2[19]="ï";
    arr1[20]="&lt;";     arr2[20]="<";
    arr1[21]="&ntilde;"; arr2[21]="ñ";
    arr1[22]="&oacute;"; arr2[22]="ó";
    arr1[23]="&ocirc;";  arr2[23]="ô";
    arr1[24]="&ograve;"; arr2[24]="ò";
    arr1[25]="&oslash;"; arr2[25]="ø";
    arr1[26]="&otilde;"; arr2[26]="õ";
    arr1[27]="&ouml;";   arr2[27]="ö";
    arr1[28]="&szlig;";  arr2[28]="ß"; 
    arr1[29]="&uacute;"; arr2[29]="ú";
    arr1[30]="&ucirc;";  arr2[30]="û";
    arr1[31]="&ugrave;"; arr2[31]="ù";
    arr1[32]="&uuml;";   arr2[32]="ü";
    arr1[33]="&yacute;"; arr2[33]="?";
    arr1[34]="&yuml;";   arr2[34]="ÿ";
    arr1[35]="&Omega;";  arr2[35]="?";
    len = arr1.length;

    function entityToTxt(src)
    {
        src1 = src.split(" ");
        len1 = src1.length;
        for(var n=0;n!=len1;n++)
        {
            for(var m=0;m!=len;m++)
            {
                if(src1[n] == arr1[m]) src1[n] = arr2[m];
            }
        }
    xmlText.text = src1.join(" ");
    };*/ 

  10. #10
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    my bad - need to update that php file

    this line in php needs changing -
    print "&returnMe=File saved&file=".$mybody."&"; // not $body as in original

    the returned variable/value is then -- file=blah...

  11. #11
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    for an approach where entire file is loaded from flash and sent back, you need to be absolutely sure that this cannot happen simultaneously from two users

    Musicman

  12. #12
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Hi Musicman,
    i remember reading somewhere of a php script that safeguards against the above.

    if i recall correctly, php is used to write a timestamped file and this is compared to the
    main file, and only when the main file is seen to be free to write to, the data is
    transferred and the timestamp file is removed.

    i cannot remember where i have seen this.
    do you have any idea where this info. might lie ?

  13. #13
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    You don't want to be passing that entire XML file back and forth. That's a mess and unnecessary.

    The only thing really wrong that I can see is that you're loading and saving the file via HTTP. The loading may be an issue if your php.ini file allows that to happen, but I doubt Yahoo is allowing it. You don't need to be doing that though. Just keep the request locally on the file system. Like:
    PHP Code:
    $xdoc->load('sermons/xmlTest.xml');
    ...
    $xdoc->save('sermons/xmlTest.xml'); 
    Try using the SimpleXML class if you are still having troubles. More than likely it's there for you to use. if it is, you simply have a call to: simplexml_load_file() to load in the file, then you have a SimpleXML object to work with. The documentation is pretty nice and easy to use: http://us.php.net/simplexml

  14. #14
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Hi Taco,
    just to clarify, the example provided, although messy, is meant to be used as an admin
    file for updating an xml file. There is no need to pass the xml back to the admin file,
    that is simply added there to show that it can be done.

    I use this method in my xmlAdmin.swf to update the xml that is read by my other .swf
    files. My xmlAdmin file also passes the name of the xml file to open and save to, so it is
    useful, to me, for altering all files on my sites that depend on regular xml updates.

    Thanks for the link to SimpleXML, I'll take a good look at that. (there goes Sunday)

  15. #15
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    @Taco
    Yahoo hosting, at least the hosting that this site is on, does not support SimpleXML functions in PHP. So, that's a bummer.

    Anyway, I got it working. I'll post my PHP and the relevant AS3 code here. FYI, I only partially used your method a_modified_dog. It wasn't because your method isn't good, just because I couldn't make it work. It's more because of my lack of knowledge with PHP. Anyway, here's the finished code.

    writeit2.php
    PHP Code:

    <?php
    if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){
        
    $xml $GLOBALS["HTTP_RAW_POST_DATA"];
        
    $file fopen("/sermons/songs.xml","w");
        
    fwrite($file$xml);
        
    fclose($file);
        
    //echo("<status>File saved.</status>");
        
        
    echo($GLOBALS["HTTP_RAW_POST_DATA"]);
    }
    ?>
    putfile.php
    PHP Code:
    <?php

    $filename 
    $_FILES['Filedata']['name'];    
    $filetmpname $_FILES['Filedata']['tmp_name'];    
    $fileType $_FILES["Filedata"]["type"];
    $fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 1000);

    move_uploaded_file($_FILES['Filedata']['tmp_name'], "/sermons/sermons/".$filename);

    ?>
    relevant Actionscript
    PHP Code:

    // Set the URL for the PHP uploader scripts
    var myUrl:URLRequest = new URLRequest("writeit2.php");
    var 
    url2:URLRequest = new URLRequest("putFile.php");


    //reads in the current XML document in order to add to it
    function readXML():void
    {
        
    //xmlText.text = "reading xml file";
        
    var vers:* = new Date().getTime();
        
        var 
    myLoader:URLLoader = new URLLoader();
        
        
    myLoader.addEventListener(Event.COMPLETExmlLoaded);

        
    myLoader.load(new URLRequest(path+"songs.xml"));
    };


    // Function that fires off when the user presses the "done" btn... begins the process of uploading the MP3 file
    function uploadVars(e:MouseEvent):void 
    {
        
    mcSermonsPage.mcBlocker.visible false;
        
        
    fileRef.upload(url2);
        
    mcSermonsPage.btnDone.visible false;
        
    readXML();
    }


    //called when the current XML document is loaded and ready for addition
    function xmlLoaded(e:Event):void
    {
        if(
    runCount <= 1)
        {
            
    myXML = new XML(e.target.data);
            list = new 
    XMLList(myXML);
        }
        
        var 
    node:XMLNode = new XMLNode(1"song")
        
        var 
    urlNode:XMLNode = new XMLNode(1"url");
        var 
    urlText:XMLNode = new XMLNode(3"sermons/"+mcSermonsPage.txtFilename.text)
        
    urlNode.appendChild(urlText);
        
    node.appendChild(urlNode)

        var 
    preacherNode:XMLNode = new XMLNode(1"preacher");
        var 
    preacherText:XMLNode = new XMLNode(3mcSermonsPage.txtSpeaker.text)
        
    preacherNode.appendChild(preacherText);
        
    node.appendChild(preacherNode)

        var 
    dateNode:XMLNode = new XMLNode(1"date");
        var 
    dateText:XMLNode = new XMLNode(3mcSermonsPage.txtDate.text)
        
    dateNode.appendChild(dateText);
        
    node.appendChild(dateNode)

        var 
    titleNode:XMLNode = new XMLNode(1"title");
        var 
    titleText:XMLNode = new XMLNode(3mcSermonsPage.txtTitle.text)
        
    titleNode.appendChild(titleText);
        
    node.appendChild(titleNode)

        
        list.
    appendChild(node);

    };

    // Function that fires off when the MP3 File is selected from PC and Browse dialogue box closes
    function syncVariables(e:Event):void 
    {
        
    mcSermonsPage.txtFilename.text "" fileRef.name;
        
    mcSermonsPage.btnDone.visible true;
        
    mcSermonsPage.mcProgress.width 1;

        var 
    variables:URLVariables = new URLVariables();
        
    variables.body myXML;
        
    url2.data variables;
        
    url2.method URLRequestMethod.POST;
    }

    // Function that fires off when the upload of the MP3 file is complete... this function uploads the XML
    function completeHandler(e:Event):void 
    {
        
    myUrl.method URLRequestMethod.POST;
        
    myUrl.data myXML;
        
    myUrl.contentType "text/xml";
        
        var 
    xmlLoader:URLLoader = new URLLoader();
        
    xmlLoader.load(myUrl);

        
    xmlLoader.addEventListener(ProgressEvent.PROGRESSxmlProgress);

    Last edited by Taidaishar; 09-29-2009 at 09:46 AM.

  16. #16
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    I have another issue....

    Is there a certain limit on the file size that can be uploaded with this method? I mean, if we're talking 20MB, would that matter?

    The person that is trying to use this said that the file stopped uploading at 98%, 94%, and 96% each time they tried it. Is there some reason it might do this?

  17. #17
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    you need to contact your service provider to see if you php.ini file can be tweaked

    search here and Google for - php upload limit

  18. #18
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    I have seen errors starting from some 3 or 4 MB on - even though the provider adjusted the php.ini file to allow 50 MB for that domain.

    Musicman

  19. #19
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    Ok. I'll see if I can't contact my provider and see if they can update the filesize so larger files can be uploaded. Hopefully that will fix it. Thanks for the help.

  20. #20
    Junior Member
    Join Date
    Oct 2009
    Posts
    10
    Hello Taidaishar ! great post

    1 more thing..im very new to flash... i just pasted the codes inside the as3 project and it gave me alot of erros can u please upload the fla please ... thanks in advance !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center