Home  >  Article  >  Backend Development  >  Code for php online compression and decompression of SWF files (revised version)

Code for php online compression and decompression of SWF files (revised version)

WBOY
WBOYOriginal
2016-07-25 08:55:07943browse
  1. //-----------------
  2. //File name
  3. $filename = "test.swf";
  4. //Open the file
  5. $rs = fopen($filename, "r");
  6. //Read file data
  7. $str = fread($rs, filesize($filename));
  8. //Set swf header file
  9. $head = substr( $str, 0, 8);
  10. $head[0] = 'F';
  11. //Get the swf file content
  12. $body = substr($str, 8);
  13. //Compress the file content, use the highest compression level 9
  14. $body = gzcompress($body, 9);
  15. //Merge file header and content
  16. $str = $head . $body;
  17. //Close the read file stream
  18. fclose($rs);
  19. //Create A new file
  20. $ws = fopen("create.swf", "w");
  21. //Write the file
  22. fwrite($ws, $str);
  23. //Close the file
  24. fclose($ws);
  25. //-------------------
  26. ?>
Copy the code

2, decompress the swf file online

  1. //------------------
  2. //File name
  3. $filename = "1000109.swf";
  4. // Open the file
  5. $rs = fopen($filename, "r");
  6. //Read the file data
  7. $str = fread($rs, filesize($filename));
  8. //Set the swf header file
  9. $head = substr($str, 0, 8);
  10. //$head = 'F' . $head;
  11. $head[0] = 'F';
  12. /*$head[1] = ('W');
  13. $head[2] = ('S');
  14. //$head[3] = version;
  15. $head[4] = ($str % 256);
  16. $head[5] = ($str / 256 % 256);
  17. $head[6] = ($str / 256 / 256 % 256);
  18. $head[7] = ($str / 256 / 256 / 256 % 256);*/
  19. //Get swf file Content
  20. $body = substr($str, 8);
  21. //Decompress file content
  22. $body = gzuncompress($body);
  23. //Merge file header and content
  24. $str = $head . $body;
  25. / /Close the read file stream
  26. fclose($rs);
  27. //Create a new file
  28. $ws = fopen("create.swf", "w");
  29. //Write the file
  30. fwrite($ws, $str);
  31. //Close the file
  32. fclose($ws);
  33. //------------------
  34. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn