Codulle - L'explorateur de code sources

Accueil>> AlBulle >> AlBulle0.1 >> medias

Informations fichier

Nom du fichier : OMzip.php
Taille du fichier : 11 Ko (348 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 array array of files to include
  50. *
  51. * @return integer the size of the zip in bytes
  52. *
  53. * @access public
  54. */'Content-length: '/**
  55. * Size of compressed data
  56. *
  57. * @var integer $datalen
  58. *//**
  59. * Central directory
  60. *
  61. * @var array $ctrl_dir
  62. *//**
  63. * End of central directory record
  64. *
  65. * @var string $eof_ctrl_dir
  66. */"\x50\x4b\x05\x06\x00\x00\x00\x00";
  67.  
  68.  
  69. /**
  70. * Constructor : send ZIP headers
  71. *
  72. * @param string archive name
  73. * @param integer actually send the data ?
  74. *
  75. * @access private
  76. */"archive.zip"// If you're having a problem with a file download script not working with IE
  77. // if you call session_start() before sending the file, then try adding a
  78. // session_cache_limiter() call before session_start().
  79. "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');
  80. "Content-type: application/zip""Content-disposition: attachment; filename=\"$name\""/**
  81. * Converts an Unix timestamp to a four byte DOS date and time format (date
  82. * in high two bytes, time in low two bytes allowing magnitude comparison).
  83. *
  84. * @param integer the current Unix timestamp
  85. *
  86. * @return integer the current date in a four byte DOS format
  87. *
  88. * @access private
  89. */'year''year''mon''mday''hours''minutes''seconds'] = 0;
  90. } // end if
  91. 'year''mon''mday''hours''minutes''seconds'] >> 1);
  92. } // end of the 'unix2DosTime()' method
  93.  
  94.  
  95. /**
  96. * Sends a file to stdout, using output control, megabyte per megabyte.
  97. * Useful when readfile or passthru corrupt data, and supposed to be more efficient, but
  98. * consumes PHP execution time.
  99. *
  100. * @param string file path
  101. *
  102. * @return boolean success
  103. *
  104. * @access private
  105. */// how many bytes per chunk
  106. $buffer = '''rb'/**
  107. * Adds file to archive
  108. *
  109. * @param filename content file to add
  110. * @param string name of the file in the archive (may contains the path)
  111. * @param boolean whether or not to compress the data CAUTION: file must fit in RAM if "true" !
  112. * @param integer the current timestamp
  113. *
  114. * @return boolean success of operations
  115. *
  116. * @access public
  117. */'./', '''\\', '/', $name)) , "CP1252", "CP437"'./', '''\\', '/''\x''\x''\x''\x''$hexdtime = "''";');
  118.  
  119. $fr1 = "\x50\x4b\x03\x04";
  120. $fr1 .= "\x14\x00"; // ver needed to extract
  121. $fr1 .= "\x00\x00"; // gen purpose bit flag
  122. "\x08\x00"; // compression method
  123. "\x00\x00"; // compression method
  124. // last mod time and date
  125. // "local file header" segment
  126. // fix crc bug
  127. // crc32 that reads byte per byte the file
  128. 'V', $crc); // crc32
  129. 'V'// compressed filesize
  130. 'V'// uncompressed filesize
  131. 'v'// length of filename
  132. 'v', 0); // extra field length
  133. // send this !
  134. // "file data" segment
  135. // now add to central directory record
  136. $cdrec ="\x50\x4b\x01\x02";
  137. $cdrec .= "\x00\x00"; // version made by
  138. $cdrec .= "\x14\x00"; // version needed to extract
  139. $cdrec .= "\x00\x00"; // gen purpose bit flag
  140. "\x08\x00"; // compression method
  141. "\x00\x00"; // compression method
  142. // last mod time & date
  143. 'V', $crc); // crc32
  144. 'V'// compressed filesize
  145. 'V'// uncompressed filesize
  146. 'v'// length of filename
  147. 'v', 0 ); // extra field length
  148. 'v', 0 ); // file comment length
  149. 'v', 0 ); // disk number start
  150. 'v', 0 ); // internal file attributes
  151. 'V', 32 ); // external file attributes - 'archive' bit set
  152. 'V'// optional extra field, file comment goes here
  153. // save to central directory
  154. // end of the 'addFile()' method
  155.  
  156.  
  157. /**
  158. * Dumps out end of ZIP
  159. *
  160. * @access public
  161. */'''v'// total # of entries "on this disk"
  162. 'v'// total # of entries overall
  163. 'V'// size of central dir
  164. 'V', $this -> datalen) . // offset to start of central dir
  165. "\x00\x00"; // .zip file comment length
  166. // end of the 'file()' method
  167.  
  168. } // end of the 'zipfile' class
  169.  

Liste des projets

Téléchargez Codulle

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