It is sometimes useful to decompressed SWF files, for example if you want to process it usin ffmpeg.
I wrote this function because I didn't want to call en external program (like cws2fws)
<?php
/**
* convert compressed swf to uncompressed. usefull for ffmpeg usage
* @param string $in_swf_file input file to convert
* @param string $out_swf_file converted output file
* @param string $error error message
* @return boolean true or false
* see more info at http://the-labs.com/MacromediaFlash/SWF-Spec/SWFfileformat.html
* and a perl version at http://zefonseca.com/cws2fws/release/cws2fws
*/
function decode_swf($in_swf_file, $out_swf_file, &$error) {
$swf = file_get_contents($in_swf_file); // read entire file
if (!$swf) {
$error = "SWF file not fount - $in_swf_file";
return FAIL;
}
$type = substr($swf, 0, 3); // already in uncompressed format?
if ($type == 'FWS') {
@copy ($in_swf_file, $out_swf_file);
return SUCCESS;
}
if ($type != 'CWS') {
$error = "Wrong file format - $in_swf_file";
return FAIL;
}
$uncomp = gzuncompress (substr($swf, 8)); // unzip everything but the header
if (!$uncomp) {
$error = "File data error - $in_swf_file";
return FAIL;
}
$header = substr($swf, 0, 8);
$header[0] = 'F'; // CWS -> FWS
$status = file_put_contents($out_swf_file , $header . $uncomp);
if (!$status) {
$error = "File write error - $out_swf_file";
return FAIL;
}
return SUCCESS;
}
?>
FAQ: Frequently Asked Questions
FAQ
jbrnra at gmail dot com
18-Oct-2008 11:13
18-Oct-2008 11:13
Anonymous
10-Jul-2008 08:40
10-Jul-2008 08:40
You can contribute your notes to the PHP manual from the comfort of your browser! Just add your comment in the big field below, and, optionally, your email address or name in the little one. After submission, your note will appear under the documentation as a part of the manual.
There is no need to obfuscate your email address, as we have a simple conversion in place to convert the @ signs and dots in your address. You may still want to include a part in the email address only understandable by humans, to make it spam protected, as our conversion can be performed the other way too. You may submit your email address as user@NOSPAM.example.com for example (which will be displayed as user at NOSPAM dot example dot com. Although note that we can only inform you of the removal of your note, if you use your real email address.
Note that HTML tags are not allowed in the posts, but the note formatting is preserved. URLs will be turned into clickable links, PHP code blocks enclosed in the PHP tags <?php and ?> will be source highlighted automatically. So always enclose PHP snippets in these tags. (Double-check that your note appears as you want during the preview. That's why it is there!)
Please read the following points carefully before submitting your comment. If your post falls into one of the categories mentioned there, it will be rejected by one of the editors.
vlad-45 at voliacable dot com
15-Jan-2008 07:42
15-Jan-2008 07:42
I spend too much time with session_set_save_handler() but could not use it.
I work with Apache/1.3.12 (Win32) PHP/5.1.2 in local mode, if it matters. I want to use handler destroy() but it does not
work. If I need to determine all handlers, then I have a problem with write().
Function write() does not want to create and open storage file. If file created outside the
function, it still would not be opened. Actually, write() refuses to create any file. But debug output shows
that write() was called and had all the necessary data.
This problem can be solved by removing of function write(). Session will create storage file and write
data in it. But function destroy() refuses to work in any case. (It's the only function I need.)
After closing of browser the storage file remains and file
temp (debug output) is absent.
Maybe closing of browser does not mean end of session (although next time the session id will be different),
but let's see how function write() works:
<?php
function open($save_path, $session_name)
{
global $sess_save_path;
$sess_save_path = $save_path;
echo "$session_name successfully opened<br>"; ////debug
return(true);
}
function close()
{
return(true);
}
function read($id)
{
global $sess_save_path;
$sess_file = "$sess_save_path/sess_$id";
return (string) @file_get_contents($sess_file);
}
function write($id, $sess_data)
{ echo "write begin<br>"; //////debug
global $sess_save_path;
$sess_file = "$sess_save_path/sess_$id";
echo "$sess_file<br>"; ////debug
echo "$sess_data<br>"; /////debug
if ($fp = @fopen($sess_file, "w"))
{
$return = fwrite($fp, $sess_data);
fclose($fp);
return $return;
}
else
{ echo "did not open file for writing<br>"; //////debug
return(false);
}
}
function destroy($id) // works in no case
{
global $sess_save_path;
$f = @fopen("./tmp/temp", "w"); /////debug
$sess_file = "$sess_save_path/sess_$id";
return(@unlink($sess_file));
}
function gc($maxlifetime)
{
global $sess_save_path;
foreach (glob("$sess_save_path/sess_*") as $filename) {
if (filemtime($filename) + $maxlifetime < time()) {
@unlink($filename);
}
}
return true;
}
session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
session_save_path("./tmp"); // temporary storage
session_name("counter");
session_start();
//$id = session_id(); //If I use these 3 strings, file will be created,
//$sess_file = "$sess_save_path/sess_$id"; // but would not be opened by write() all the same.
//$fp = @fopen($sess_file, "w"); // file will be empty
if (!(session_is_registered("someVar"))) // new session
{ echo "someVar not registered<br>"; ////debug
session_register("someVar"); // session variable
$_SESSION["someVar"] = "someValue";
}
echo "it still works<br>"; ////debug
?>
File temp was not created.
A storage file was not created and output in browser was as follows:
counter successfully opened
someVar not registered
it still works
write begin
./tmp/sess_a4bc6c82ab15635de77bd0c9c74b13d4
someVar|s:9:"someValue";
did not open file for writing
Who could explain this phenomenom?
langjairich at yahoo dot com
17-Dec-2006 06:41
17-Dec-2006 06:41
Here's how I successfully installed PHP 5.2 with my IIS 5.1:
1) Install with the option: "IIS 4+ / ISAPI"
2) Install under folder "C:\PHP\"
3) Edit the file: "C:\WINDOWS\php.ini"
Change "doc_root = " to "doc_root = c:\inetpub\"
4) Open IIS, right click on home page, properties.
Click "home directory" tab.
Click Configuration, look for the extension ".php".
The executable path should be "C:\PHP\php5isapi.dll"
5) Restart IIS.
Enjoy. I had to learn the hard way. Took me 2 days.
adriaan at vannatijne dot nl
30-Jul-2005 12:48
30-Jul-2005 12:48
A dutch FAQ;
www.yapf.net
A dutch site about PHP;
www.phpfreakz.nl