SWF src= file.php

i'm making a flash music player for myspace.com
users will visit my site and create an account for uploading their own music file.
they will be given <embed> code to put into their page based on a primary key that is assigned in mysql when their account is setup. so it will read simiar to:
<embed src="http://www.somedomain.com/flashplayer.php?id=3">

once that php file is src'd by the player, the php will search my database based on the "id" passed and then set the actual SWF source for the flash player somewhere in the php header.

the problem is, i don't know how to do this exactly.

can i just use regular $_REQUEST["id"] to get the id? second... how do i set up the header information so that the "file.swf?someattribute=somevalue" src is what the <embed> src reads?

i'm pretty sure this is possible and not to difficult, but i don't know the code to accomplish it...

Jeremy DaleySenior DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I havn't tested this - my FTP server just went down.
I use this code with PDFs and it works fine.  I've changed the content-type to be the proper for SWF files - so it should work.

The only thing to keep in mind with this is to use it with small files only.  This reads the entire file into memory before it sends it out.  

      $filename = 'test.swf';
      $fle = file_get_contents($filename);
      $len = filesize($filename);
              header('Content-type: application/x-shockwave-flash');
            header('Content-Length: ' . $len);
            header('Content-Disposition: inline; filename=' . $flashname);
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
      echo $fle;
Jeremy DaleySenior DeveloperAuthor Commented:
okay, let me try that when i get off work... i'll let ya know the outcome

No problem.  I was able to finally test it - it worked fine for me here.
- just to let you know.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Jeremy DaleySenior DeveloperAuthor Commented:
okay, here's the situation:

it seems to work fine when all i'm doing is using a raw file (i.e. "somefile.swf")

but what i have to do is pass variables to the flash player in the file string. for example, a user can specify what color they want the player to be. i put that value in the database when they're setting their preferences for the player's attributes.

when the php file is called, it checks the database and passes that color value in the file extension like so: "somefile.swf?playerColor=red"

when i add that variable to the end, it doesn't work at all.

i don't know of any other way to get those variables to the flash player. things like artist and song title are also passed in that file string.
You won't be able to pass command line info to the player with the method above.
Are you handing out code snips to people so they can add your flash file to their site?
Or are you trying to personalize logins for individual users on your site only?
Basically - do you have control over the object embed tag for the flash file being called?
Sorry - just re-read your question above.  You are handing out the object tag to users...
I have a solution - but you will need .fla source control over the flash file being used.
Can you edit the flash file?
Jeremy DaleySenior DeveloperAuthor Commented:
yes, i have the source file.
Okay - pass out a similar object tag to your users as below:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="flashplayer" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="flashplayer.php?id=3" />
<param name="FlashVars" value="id=3">
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="flashplayer.php?id=3" FlashVars="id=3" quality="high" bgcolor="#ffffff" width="550" height="400" name="flashplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />

Now you can use the FlashVars in actionscript to set the unique id from the user - use the lines param name="FlashVars" and in the embed source - point to the same variable name.

Now you can use a LoadVars call from flash to pull data from another PHP page - passing the user's id to the second page.

var my_lv:LoadVars = new LoadVars();
my_lv.onLoad = function(success:Boolean):Void {
    if (success) {
    } else {
my_lv.load("http://www.site.com/flashparams.php?id=" + id);

Hope this makes sense - it's untested but I can try to walk you through any problems.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeremy DaleySenior DeveloperAuthor Commented:
okay... i'll try it after work... i may need clarification once i get it started.

Jeremy DaleySenior DeveloperAuthor Commented:
will the flashparams just be plain text... or how does that work in flash?
Just like any variable - actionscript changes the type based on content.  If you try to add a variable to another like a + b they will either be treated as numbers or strings - depending on what's in them:
(a+b = 3)


Etc.  So if you need to pass string - it works fine as well.  If you want to be able to pass a filename to a user then you probably want to have control to change that yourself.  If you simply told them to use an embed command on their page that had the file name embedded - then you won't be able to change it without getting them to edit their web page for each file.
Jeremy DaleySenior DeveloperAuthor Commented:
instead of using a php src... couldn't i just use the swf file with:

and then in the actionscript, send the same:
my_lv.load("http://www.site.com/flashparams.php?id=" + id);

... do my database lookup from that php? turn it into a text file from "header" commands?
... uh .... yes....

Yeah.  The only thing I can see as a benefit from generating a dynamic swf would be that the users will never know where the actual swf file is located on your site.  But - they would still be able to grab the file from their cache and host it directly.  So - there is no real benefit.

Good call on that - completely missed the obvious :)
Jeremy DaleySenior DeveloperAuthor Commented:
well, i ended up using the sendAndLoad command instead. it was pretty easy for me to just:

onClipEvent (load) {
      $envelope = new LoadVars();
      $envelope_received = new LoadVars();
      $id = _root.id;
      $envelope.id = $id;
                              //stuff to do when vars are received back from php file
                             var someVar = $envelope_received.var1;
      $envelope.sendAndLoad("myspace_player.php", $envelope_received,"GET");

my php file just used:


i did some mysql calls and then just echoed out a string of vars attached in one line:

echo "var1=value1&var2=value2";

the flash just picks up the echo

your method pretty much got me on the track i needed. i looked into the actionscript dictionary a bit more and picked up that method instead cause it seemed a little easier for me.
Most people don't have access to the source of the flash files they use - I completely missed the obvious.
I'm glad I could help even if it was a round about -way.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.