Codulle - L'explorateur de code sources

Accueil>> AlBulle >> Albulle1.0rc1 >> core >> includes >> classes

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

Liste des projets

Téléchargez Codulle

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