Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SWF src= file.php

Posted on 2006-03-26
16
Medium Priority
?
652 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:Jeremy Daley
  • 9
  • 7
16 Comments
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 16302230
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;
?>
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16302838
okay, let me try that when i get off work... i'll let ya know the outcome

thanks
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 16302866
No problem.  I was able to finally test it - it worked fine for me here.
- just to let you know.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16307532
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.
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 16310807
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?
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 16310823
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?
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16311631
yes, i have the source file.
0
 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 600 total points
ID: 16311800
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" />
</object>

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) {
        trace(this.fileName);
    } else {
        trace("Error");
    }
}
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.
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16311982
okay... i'll try it after work... i may need clarification once i get it started.

thanks
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16311991
will the flashparams just be plain text... or how does that work in flash?
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 16312119
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.
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16312799
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?
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 16312811
... uh .... yes....

;)
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 16312836
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 :)
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16329326
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.
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 16332271
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.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question