Sunday, November 8, 2009

Flash caching PHP response

Recently I ran into an issue where I would call a PHP file that would generate a unique id and return that to Flash (I am sure I could do the same thing from within flash but decided to just use PHP's uniqid to solve this for now) The id that comes back is used for files the user is uploading. The problem I noticed is that Flash would make the call to the PHP file and then get back the same UUID everytime. I thought that perhaps Flash was caching the page and then just loading it instead of re-requesting it from the web server. In summary this was somewhat true. The page was being cached somewhere and needed some PHP header references to prevent from caching properly.


Problem:
Flash kept loading the same values from a PHP script that should have been generating different values on every call.

Solution:
I included these header functions and parameters at the top of my PHP file.
header( "Pragma: no-cache" );

header( "Cache-Control: no-cache" );

header( "Expires: Sat, 01 Jan 2000 00:00:00 GMT" );

 Happy programming.

Getting file extension with ActionScript

It has been some time since I have posted, but I figured this one quick function for extracting a file extension was worth a quick post.

Problem:
You are dealing with files and want a quick way to extract the files extension.

Solution:
A simple function that will return back you to the extension of any file with or without a full path reference preceding it is this:
function getFileExtention(str:String):String{
    return str.substring(str.lastIndexOf(".") + 1, str.length);
}
NOTE: This will not account for URLs that have GET parameters on the end of them. To do this, Google search getting file extension using regexp or regular expressions.

 I hope this helps someone who is looking for a quick solution online. Good luck.