2009/03/21
swfmill の Windows ローカルテスト環境を
最近 MacBookPro を買ってやっぱり Windows として使ってます。しかし、EMOBILE (細くない方のPCカードタイプ)がささらず外出時はサーバー確認できないのが困ります。ここはローカル環境を整備するしかないと思い、XAMPP と windows 用の swfmill を入れてみたのですが、うまく swf をはいてくれない・・・
swf をバイナリエディタで開いたところでやっとわかりました。入力されたSWFの"0A"が"0D0A"として出力されてます。パイプ処理をかましたからだと思いますが、Windowsの改行を変換すれば解決。 ・・・ こんなんしなくてもMacなら普通に環境を作れると思いますが。
<?
header('Content-type: application/x-shockwave-flash');
echo xml2swf(swf2xml('test.swf'));
function xml2swf($xml){
$is_xampp = in_array('xampp',explode('/',$_SERVER["DOCUMENT_ROOT"]))>0;
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "error.log", "a"),
);
if($is_xampp){
$cmd = '/xampp/htdocs/www/bin/swfmill xml2swf stdin stdout';
}else{
$cmd = '/usr/local/bin/swfmill xml2swf stdin stdout';
}
$process = proc_open($cmd, $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $xml);
fclose($pipes[0]);
$swf = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
if($is_xampp) $swf = str_replace("\r\n","\n",$swf);
}else{
$swf = null;
}
return($swf);
}
function swf2xml($swf){
$is_xampp = in_array('xampp',explode('/',$_SERVER["DOCUMENT_ROOT"]))>0;
if($is_xampp){
$process = popen('/xampp/htdocs/www/bin/swfmill swf2xml '.$swf,'r');
if (is_resource($process)) {
$xml = stream_get_contents($process);
pclose($process);
}else{
$xml = null;
}
}else{
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "error.log", "a"),
);
$process = proc_open('/usr/local/bin/swfmill swf2xml stdin stdout', $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], file_get_contents($swf));
fclose($pipes[0]);
$xml = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
}else{
$xml = null;
}
}
return($xml);
}
コメント一覧