Link to home
Create AccountLog in
Avatar of Jeremy Daley
Jeremy DaleyFlag for United States of America

asked on

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...

thanks,
jeremy
Avatar of Rob_Jeffrey
Rob_Jeffrey

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.  

<?php
      $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;
?>
Avatar of Jeremy Daley

ASKER

okay, let me try that when i get off work... i'll let ya know the outcome

thanks
No problem.  I was able to finally test it - it worked fine for me here.
- just to let you know.
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?
yes, i have the source file.
ASKER CERTIFIED SOLUTION
Avatar of Rob_Jeffrey
Rob_Jeffrey

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
okay... i'll try it after work... i may need clarification once i get it started.

thanks
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=1;
b=2;
(a+b = 3)

a="d";
b="f";
(a+b="df")

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.
instead of using a php src... couldn't i just use the swf file with:
src="flashplayer.swf?id=3"

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

... 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 :)
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;
      $envelope_received.onLoad=function(){
                              //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:

$id=$_GET["id"];

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.
Definately.
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.