Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12

Thread: Php to flash

  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Php to flash

    I hope someone can help.
    I need some help linking flash and php.
    I have the following actionscript code that limits file types to a given set. I can comment out those I don't want. However I would like to be able to set the file types dynamically from a PHP file and I have no idea how to do that.

    Code:
    var allTypes:Array = new Array();
    
    var imageTypes:Object = new Object();
    imageTypes.description = "Authorised files  (*.JPG;*.JPEG;*.JPE;*.GIF;*.PNG;*.tiff;*.tif;*.zip;*.rar;*.doc;*.pdf;*.xls;*.sit;*.ppt;*.csv;*.txt;*.rtf;)";
    imageTypes.extension = "*.jpg; *.jpeg; *.jpe; *.gif; *.png; *.tif; *.tiff; *.zip; *.rar;  *.doc; *.pdf;  *.xls; *.ace; *.sit; *.ppt; *.csv; *.txt;*.rtf;";
    allTypes.push(imageTypes);
    /*
    var imageTypes:Object = new Object();
    imageTypes.description = "Images (*.JPG;*.JPEG;*.JPE;*.GIF;*.PNG;*.tiff;*.tif;)";
    imageTypes.extension = "*.jpg; *.jpeg; *.jpe; *.gif; *.png;*.tiff;*.tif;";
    allTypes.push(imageTypes);
    
    var imageTypes:Object = new Object();
    imageTypes.description = "Archives (*.zip;*.rar;*.ace;*.sit;)";
    imageTypes.extension = "*.zip; *.rar; *.ace; *.sit;";
    allTypes.push(imageTypes);
    
    var textTypes:Object = new Object();
    textTypes.description = "Text Files (*.TXT;*.RTF;)";
    textTypes.extension = "*.txt; *.rtf;";
    allTypes.push(textTypes);*/
    
    var FLRef:FileReferenceList = new FileReferenceList();
    I am assuming I should import a variable i.e.

    var textTypes:Object = new Object();
    textTypes.description = VariableDesc;
    textTypes.extension = VariableExt;
    allTypes.push(textTypes);

    where (from the php file)
    $VariableDesc = "Text Files (*.TXT;*.RTF; )";
    $VariableExt = "*.txt; *.rtf";

    Any suggestions, thanks?
    Last edited by mhodgson; 02-02-2009 at 12:44 PM.

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You could do one of two things. First is to have PHP output the list of file extensions as a string for Flash, and then have Flash split the string based on something like the | sign.

    Or you can implement AMPHP http://www.amfphp.org/ which is a much more expansive solution. If you plan on doing more with Flash and PHP, this is a good suggestion.

    If you are just trying to do this one thing, I would just use loadVars() and load a PHP file which will export the list as a string and split the string.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the suggestion.
    Managed to find an example to modify and it seems to work

    Code:
    var allTypes:Array = new Array(); // create an array of file types
    
    var imageTypes:Object = new Object();
    var files_types:LoadVars = new LoadVars();
    
    files_types.onLoad = function (success:Boolean):Void {
        if (success) {
            imageTypes.description = files_types.filetypes;
            imageTypes.extension = files_types.fileextension;
        } else {
            
    		imageTypes.description = "Authorised files  (*.JPG;*.JPEG;*.JPE;*.GIF;*.PNG;*.tiff;*.tif;*.zip;*.rar;*.doc;*.pdf;*.xls;*.sit;*.ppt;*.csv;*.txt;*.rtf;)";
    		imageTypes.extension = "*.jpg; *.jpeg; *.jpe; *.gif; *.png; *.tif; *.tiff; *.zip; *.rar;  *.doc; *.pdf;  *.xls; *.ace; *.sit; *.ppt; *.csv; *.txt;*.rtf;";
    
        }
    }
    files_types.load( _root.urlUpload="../file_types.txt"); // Get the file
    
    /* contents of params.txt:
        &filetypes=Archives (*.zip;*.rar;*.ace;*.sit; *.gif;)&fileextension=*.zip; *.rar; *.ace; *.sit; *.gif;
    */
    
    allTypes.push(imageTypes); // add image types to array
    Not sure it is as neat or correct as it could be as this is my first taste of actionscript.

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Looks good!

    Here you can change the file from file_types.txt to file_types.php, so long as the PHP file outputs the same kind of string.

    Code:
    files_types.load( _root.urlUpload="../file_types.php"); // Get the file
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, quite pleased with myself on that.

    If I change the extension from .txt to .php does that mean I can put in some php code to select data dynamically?
    i.e.
    if ($variable == 'text') {
    filetypes=Text Files (*.TXT;*.RTF; )
    fileextension=*.txt; *.rtf
    }
    elseif ($variable == 'archive') {
    filetypes=Archives (*.zip;*.rar;*.ace;*.sit; *.gif; )
    fileextension=*.zip; *.rar; *.ace; *.sit; *.gif;
    }
    and so on....
    Last edited by mhodgson; 02-03-2009 at 02:12 PM.

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Correct, as long as your PHP outputs only the string in this format "&variable=stringstringstring", you can do any kind of preprocessing you wish in the PHP. Flash only will see the string that you echo at the end.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #7
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I get it, only the following code does not work. It's fine when viewing the php page in webpage but flash only sees the last statement (the else bit).

    Code:
    <?php 
    $variable = "text"; // set a testing value for the variable
    
    if ($variable == 'text') {
    $filetype = '&filetypes=Text Files (*.TXT;*.RTF; )';
    $fileext = '&fileextension=*.txt; *.rtf';
    
    }
    elseif ($variable == 'archive') {
    $filetype = '&filetypes=Archives (*.zip;*.rar;*.ace;*.sit; *.gif; )';
    $fileext = '&fileextension=*.zip; *.rar; *.ace; *.sit; *.gif;';
    }
    elseif ($variable == 'images') {
    $filetype = '&filetypes=Images (*.JPG;*.JPEG;*.JPE;*.GIF;*.PNG;*.tiff;*.tif; )';
    $fileext = '&fileextension=*.jpg; *.jpeg; *.jpe; *.gif; *.png;*.tiff;*.tif;';
    }
    else{
    $filetype = '&filetypes=Authorised files  (*.JPG;*.JPEG;*.JPE;*.GIF;*.PNG;*.tiff;*.tif;*.zip;*.rar;*.doc;*.pdf;*.xls;*.sit;*.ppt;*.csv;*.txt;*.rtf;*.xdoc; )';
    $fileext = '&fileextension=*.jpg; *.jpeg; *.jpe; *.gif; *.png; *.tif; *.tiff; *.zip; *.rar;  *.doc; *.pdf;  *.xls; *.ace; *.sit; *.ppt; *.csv; *.txt;*.rtf;';
    }
    
    echo $filetype.$fileext; 
    
    ?>

  • #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You mean PHP outputs

    Code:
    &filetypes=Text Files (*.TXT;*.RTF; )&fileextension=*.txt; *.rtf
    but Flash outputs

    Code:
    &filetypes=Authorised files (*.JPG;*.JPEG;*.JPE;*.GIF;*.PNG;*.tiff;*.tif;*.zip;*.rar;*.doc;*.pdf;*.xls;*.sit;*.ppt;*.csv;*.txt;*.rtf;*.xdoc; )&fileextension=*.jpg; *.jpeg; *.jpe; *.gif; *.png; *.tif; *.tiff; *.zip; *.rar;  *.doc; *.pdf;  *.xls; *.ace; *.sit; *.ppt; *.csv; *.txt;*.rtf;
    Also I think you might want to consider using a different deliminator than ; I like the | myself. That might help here and do you really need an * in front of them all?

    I would think that this type of a string would be easier to process later in Flash. You could always pop the first entry as the title and then each of the rest as file extensions. I can't seem to find it, but I know there are a few characters that might cause some issues when used (of course & because it notes a new variable, so it must be urlencoded if you use it in your text).

    Code:
    &filetypes=Authorised files|.JPG|.JPEG|.JPE&fileextension=.jpg|.jpeg|.jpe|.gif
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #9
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes that's exactly the problem.

    I have implimented your other suggestions, makes no difference though.

    It is for a flash upload system but I want the type of files that can be uploaded to be limited dpending on where the user is coming from. I.e. if uploading to a gallery only images, uploading documents only textfiles/pdf etc. I would like to make it easy for the site admin to change the allowed extensions if need be, which is why I thought of an external file.

    I could simply use seperate upload systems for each part of the site I suppose but that seems wasteful.

    Maybe an easier solution would be to call a different external file i.e for the gallery call galleryfiles.txt, for documents call documentfiles.txt though again that seems more complicated.

  • #10
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Can I see the Flash and the PHP page online somewhere? Or can you provide the source files to test?
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #11
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have found the problem... and it is almost too embarassing to admit..but then this is my first attempt at flash stuff..
    I think it was actually working all along.
    The problem seems to be that when testing the flash movie (in flash) it was not parsing the php - which I get (finally), so I was checking it in the browser as well.
    However I have just found that when testing the php page that includes the flash movie I need to close the page and reload it completely to test any changes, whereas I have simply been refreshing the page.
    Of course it now makes sense- as the browser downloads the flash file into the temp folder and simply reuses it when I refresh the page rather than replacing it.

    Anyway it seems to be working well.

    All I now have to do is pass the correct variable to flash to tack onto the url of 'filestype.php' so it calls the correct set of extensions.

    Thanks for your help so far..
    Last edited by mhodgson; 02-04-2009 at 03:46 PM.

  • #12
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    No problem, and hey I make similar mistakes all the time and I've been doing this for a while. Sometimes I think, why doesn't think work and I scratch my head and search an hours. Come to find out, since I was testing in Flash my variable from flashvars wasn't available...duh. It happens to everyone...somedays.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.


  •  

    Posting Permissions

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