Saswat
Saswat

Reputation: 12806

Dynamically embedding a .swf file in PHP

I have a database table like this

|--------------------------------|
|   flash_file_path  |  file_type|
|--------------------------------|

Now the matter is that I want to embed a Flash video dynamically. I use a query to retrieve a video path, say:

SELECT flash_file_path FROM dt_flashvid WHERE file_type='header';

Now here's my code:

<div align="center">

<script type="text/javascript" src="swfobject.js"></script>

<div id="flashcontent">
  You must have Adobe Flash Player to run this training...
</div>

<script type="text/javascript">
    function getURLParam(strParamName){
      var strReturn = "";
      var strHref = window.location.href;
      if ( strHref.indexOf("?") > -1 ){
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
          if (
    aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
            var aParam = aQueryString[iParam].split("=");
            strReturn = aParam[1];
            break;
          }
        }
      }
      return unescape(strReturn);
    } 

   var so = new SWFObject(getURLParam("name")+".swf", getURLParam("name"), "785", "575", "8", "#FFFFFF");
   so.addParam("quality", "high");
   so.write("flashcontent");
</script>
</div>

Here we can apply the flash_file_path to get the Flash dynamically embedded, but there is a problem and it isn't working.

Upvotes: 0

Views: 1446

Answers (2)

TheTechGuy
TheTechGuy

Reputation: 17354

What you should probably do is write your code in html, and make it work (swf can be difficult to trouble-shoot). Paste it in PHP script and insert the dynamic contents where needed. Then echo the whole content. That way it is easier to debug.

Upvotes: 1

mxniu
mxniu

Reputation: 36

Why are you manually getting the parameter instead of using GET?

Also, you can just echo the new embedded swf object via php instead of using javascript and trying to mess with the div you created above.

Upvotes: 0

Related Questions