dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Reading Images File Name from Server Using PHP From Flash

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Posts
    8

    Reading Images File Name from Server Using PHP From Flash

    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.events.*;
    import flash.net.URLRequest;
    import com.imgLoader;
    //ListfilesOnServer is a list component
    //btnGetList is a button
    //txtStatusUpload is a textfield
    var filesArray:Array = new Array();
    var imageLoader:Loader = new Loader();
    var container:MovieClip = new MovieClip;




    btnGetList.addEventListener(MouseEvent.CLICK, funcaoGetList);
    function funcaoGetList(event:MouseEvent):void{
    removeEventListener(MouseEvent.CLICK, funcaoGetList);

    var lv_dados:URLVariables = new URLVariables();
    lv_dados.pathFolder = "images/";

    var objEnvia:URLRequest = new URLRequest();
    objEnvia.data = lv_dados;
    objEnvia.method = URLRequestMethod.POST;
    objEnvia.url = "http://localhost/test/readDir.php";

    var objRecebe:URLLoader = new URLLoader();
    objRecebe.dataFormat = URLLoaderDataFormat.VARIABLES;
    objRecebe.addEventListener(Event.COMPLETE, onGetListComplete);
    objRecebe.load(objEnvia);
    }
    function onGetListComplete (event:Event):void{
    trace (event.target.data.theListofFiles)
    filesArray = event.target.data.theListofFiles.split("/");
    for (var i:int=0; i< filesArray.length; i++){
    var thumbs:imgL = new imgL();
    imgLoader("images/"+filesArray[i],thumbs,i);

    }
    container.addChild(thumbs);
    addChild(container);
    //trace (container.numChildren)
    }
    var count:int = 0;
    function imgLoader(imgPath:String,rootHolder:MovieClip,numC ount:int) {
    //trace (numCount)
    var imageLoader:Loader = new Loader();
    var theURL:String = imgPath;

    var imageRequest = new URLRequest(theURL);

    imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, onComplete);
    imageLoader.load(imageRequest);

    function onComplete(evt:Event) {
    //trace (numCount)


    count++;
    trace (count)
    rootHolder.addChild(imageLoader.content);
    rootHolder.width = 60;
    rootHolder.height =60;
    rootHolder.x = count*60;
    }

    }

    PHP

    <?php
    $desired_extension1 = 'jpg'; //extension we're looking for
    $desired_extension2 = 'jpeg'; //extension we're looking for
    $path = "images/";
    $dir = opendir($path);
    $strVars;
    $VarsArray = array();

    while(false != ($file = readdir($dir)))
    {
    if(($file != ".") and ($file != ".."))
    {
    $fileChunks = explode(".", $file);
    $extLower = strtolower($fileChunks[1]); //interested in second chunk only
    if(($extLower == $desired_extension1) or ($extLower == $desired_extension2))
    {
    $VarsArray[] = $file;
    }
    }
    }
    closedir($dir);

    for ($i = 0; $i < sizeof($VarsArray); $i++)
    {
    $strVars .= $VarsArray[$i]."/";
    }

    $rest = substr($strVars, 0, -1);
    echo "theListofFiles=".$rest;
    ?>

  2. #2
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    ok thats nice code but whats the problem?
    ~calmchess~

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