Codulle - L'explorateur de code sources

Accueil>> AlBulle >> Albulle1.0rc3 >> core >> includes >> classes >> OMzip >> ConvertTables

Informations fichier

Nom du fichier : OMzip.php
Taille du fichier : 11 Ko (368 lignes)
Language : PHP

  1. span style="color: #808080; font-style: italic;">/**
  2. * On-the-fly Zip file creation class.
  3. * Makes and sends zip files without loading any file in RAM.
  4. * 2 possibilities (mixable) :
  5. * - Use compression : the file will be sent after being gzcompressed
  6. * BUT file must be able to fit in RAM for a GZ+CRC32+substr run
  7. * - No compression : the file is directly sent : little RAM usage !
  8. * Time saving, and best reactivity
  9. * ZIP is not bigger when including photos or movies
  10. * + High level API to calculate the size of the ZIP, create & send it on the fly
  11. * The download starts almost immediately, as there is no need to create the ZIP in advance
  12. *
  13. * Author/Copyright : Olivier MATHERET
  14. * matheret@free.fr http://matheret.free.fr
  15. * Licenced under CeCILL2
  16. *
  17. * Based on :
  18. *
  19. * http://www.zend.com/codex.php?id=535&single=1
  20. * By Eric Mueller <eric@themepark.com>
  21. *
  22. * http://www.zend.com/codex.php?id=470&single=1
  23. * by Denis125 <webmaster@atlant.ru>
  24. *
  25. * a patch from Peter Listiak <mlady@users.sourceforge.net> for last modified
  26. * date and time of the compressed file
  27. *
  28. * ConvertCharset.class.php from Mikolaj Jedrzejak <mikolajj@op.pl> + unicode.org tables
  29. * http://www.unicode.org Unicode Homepage
  30. * http://www.mikkom.pl Mikolaj Jedrzejak Homepage
  31. *
  32. * Reverse CRC adapted from "Reversing CRC � Theory and Practice"
  33. * HU Berlin Public Report
  34. * Martin Stigge, Henryk Plotz, Wolf Muller, Jens-Peter Redlich
  35. *
  36. * Official ZIP file format: http://www.pkware.com/appnote.txt
  37. *
  38. * @access public
  39. */'OMzip/OMcrc32.php''OMzip/ConvertCharset.class.php' );
  40.  
  41.  
  42.  
  43. /**
  44. * Creates and sends a ZIP on the fly, with no compression (just great for Jpeg/Gif/Movies)
  45. * VERY little RAM consumption, as the files never get loaded in RAM
  46. * The download starts almost immediately, as the ZIP is not created before sending
  47. *
  48. * @param name name to give to the ZIP file
  49. * @param files array of files to include
  50. * @param infiles array of new dir in the zip file for each file added
  51. *
  52. * @return integer the size of the zip in bytes
  53. *
  54. * @access public
  55. */'Content-length: '.$zipsize);
  56. // flush();
  57. /**
  58. * Size of compressed data
  59. *
  60. * @var integer $datalen
  61. *//**
  62. * Central directory
  63. *
  64. * @var array $ctrl_dir
  65. *//**
  66. * End of central directory record
  67. *
  68. * @var string $eof_ctrl_dir
  69. */"\x50\x4b\x05\x06\x00\x00\x00\x00";
  70.  
  71.  
  72. /**
  73. * Constructor : send ZIP headers
  74. *
  75. * @param string archive name
  76. * @param integer actually send the data ?
  77. *
  78. * @access private
  79. */"archive.zip"// If you're having a problem with a file download script not working with IE
  80. // if you call session_start() before sending the file, then try adding a
  81. // session_cache_limiter() call before session_start().
  82. "Pragma: public"'Content-Description: File Transfer'"Cache-Control: must-revalidate, post-check=0, pre-check=0""Content-Transfer-Encoding: binary""Expires: 0""Last-Modified: ""D, d M Y H:i:s") . " GMT""Cache-Control: private"//header('Content-Type: application/force-download');
  83. "Content-type: application/zip""Content-disposition: attachment; filename=\"$name\""/**
  84. * Converts an Unix timestamp to a four byte DOS date and time format (date
  85. * in high two bytes, time in low two bytes allowing magnitude comparison).
  86. *
  87. * @param integer the current Unix timestamp
  88. *
  89. * @return integer the current date in a four byte DOS format
  90. *
  91. * @access private
  92. */'year''year''mon''mday''hours''minutes''seconds'] = 0;
  93. } // end if
  94. 'year''mon''mday''hours''minutes''seconds'] >> 1);
  95. } // end of the 'unix2DosTime()' method
  96.  
  97.  
  98. /**
  99. * Sends a file to stdout, using output control, megabyte per megabyte.
  100. * Useful when readfile or passthru corrupt data, and supposed to be more efficient, but
  101. * consumes PHP execution time.
  102. *
  103. * @param string file path
  104. *
  105. * @return boolean success
  106. *
  107. * @access private
  108. */// how many bytes per chunk
  109. $buffer = '''rb'/**
  110. * Adds file to archive
  111. *
  112. * @param filename content file to add
  113. * @param string name of the file in the archive (may contains the path)
  114. * @param boolean whether or not to compress the data CAUTION: file must fit in RAM if "true" !
  115. * @param integer the current timestamp
  116. *
  117. * @return boolean success of operations
  118. *
  119. * @access public
  120. */'./', '''\\', '/', $name)) , "CP1252", "CP437"'./', '''\\', '/''\x''\x''\x''\x''$hexdtime = "''";');
  121.  
  122. $fr1 = "\x50\x4b\x03\x04";
  123. $fr1 .= "\x14\x00"; // ver needed to extract
  124. $fr1 .= "\x00\x00"; // gen purpose bit flag
  125. "\x08\x00"; // compression method
  126. "\x00\x00"; // compression method
  127. // last mod time and date
  128. // "local file header" segment
  129. // fix crc bug
  130. // crc32 that reads byte per byte the file
  131. 'V', $crc); // crc32
  132. 'V'// compressed filesize
  133. 'V'// uncompressed filesize
  134. 'v'// length of filename
  135. 'v', 0); // extra field length
  136. // send this !
  137. // "file data" segment
  138. // now add to central directory record
  139. $cdrec ="\x50\x4b\x01\x02";
  140. $cdrec .= "\x00\x00"; // version made by
  141. $cdrec .= "\x14\x00"; // version needed to extract
  142. $cdrec .= "\x00\x00"; // gen purpose bit flag
  143. "\x08\x00"; // compression method
  144. "\x00\x00"; // compression method
  145. // last mod time & date
  146. 'V', $crc); // crc32
  147. 'V'// compressed filesize
  148. 'V'// uncompressed filesize
  149. 'v'// length of filename
  150. 'v', 0 ); // extra field length
  151. 'v', 0 ); // file comment length
  152. 'v', 0 ); // disk number start
  153. 'v', 0 ); // internal file attributes
  154. 'V', 32 ); // external file attributes - 'archive' bit set
  155. 'V'// optional extra field, file comment goes here
  156. // save to central directory
  157. // end of the 'addFile()' method
  158.  
  159.  
  160. /**
  161. * Dumps out end of ZIP
  162. *
  163. * @access public
  164. */'''v'// total # of entries "on this disk"
  165. 'v'// total # of entries overall
  166. 'V'// size of central dir
  167. 'V', $this -> datalen) . // offset to start of central dir
  168. "\x00\x00"; // .zip file comment length
  169. // end of the 'file()' method
  170.  
  171. } // end of the 'zipfile' class
  172.  

Liste des projets

Téléchargez Codulle

Publié par Codulle - v0.1.1 - © Bubulles Creations