Question

What my php side does is load data use 'id' from database, and then show the raw data of swf files. The code of php like this:

<?php
if(isset($_GET['id']))
{
    include ('database.php');

    $record = mysql_query("SELECT `Flash`, `FlashBlob` FROM `information` WHERE `id` = '". $_GET['id'] ."'; ", $link);

    $swf = mysql_fetch_array($record);

    mysql_close($link);

    header("Content-type: " . $swf['Flash']);
    echo $swf['FlashBlob'];

    exit;
}

So if I just load the php in the web link, it goes well( the whole php page will show the flash I stored in database). In my main page, I want to load the page into my div($("#gameArea")), I have tried:

    var xmlhttp;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", 'api/swfInfo.php?id=' + id,true);
    xmlhttp.send();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById('gameArea').innerHTML=xmlhttp.responseText;
        }
    }

but the result is it load only raw data( binary data) not the flash(swf file to be shown), what should I do?

I even not sure whether I should find a flash plugin for my flash or not because I put my flash(swf file) in the database for some reason......

Please help me for the direction, thanks in advance!

Was it helpful?

Solution

Your overcomplicating the problem. If in-fact your swfInfo.php is outputting the swf file's bytes with a content type of application/x-shockwave-flash all you need to do is set the data attribute of your <object> tag to that URL.

<object type="application/x-shockwave-flash" data="api/swfInfo.php?id=7">
    <param /> <!-- parameters -->
</object>

I would also recommend a content-length declaration to ensure your connection closes properly when loading files this way.

header('Content-length: ' . mb_strlen($swf['FlashBlob']));
header('Connection: close');

OTHER TIPS

Try the following:

header('Content-Type: application/x-shockwave-flash');
header("Content-Disposition:attachment; filename="test.swf");

My questions are:

What is $swf['Flash'] ? Maybe there is the error? Have you tried your script with a file_read_content() just for debugging reasons?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top