Codulle - L'explorateur de code sources
Informations fichier
Nom du fichier : OMzip.phpTaille du fichier : 11 Ko (348 lignes)
Language : PHP
span style="color: #808080; font-style: italic;">/** * On-the-fly Zip file creation class. * Makes and sends zip files without loading any file in RAM. * 2 possibilities (mixable) : * - Use compression : the file will be sent after being gzcompressed * BUT file must be able to fit in RAM for a GZ+CRC32+substr run * - No compression : the file is directly sent : little RAM usage ! * Time saving, and best reactivity * ZIP is not bigger when including photos or movies * + High level API to calculate the size of the ZIP, create & send it on the fly * The download starts almost immediately, as there is no need to create the ZIP in advance * * Author/Copyright : Olivier MATHERET * matheret@free.fr http://matheret.free.fr * Licenced under CeCILL2 * * Based on : * * http://www.zend.com/codex.php?id=535&single=1 * By Eric Mueller <eric@themepark.com> * * http://www.zend.com/codex.php?id=470&single=1 * by Denis125 <webmaster@atlant.ru> * * a patch from Peter Listiak <mlady@users.sourceforge.net> for last modified * date and time of the compressed file * * ConvertCharset.class.php from Mikolaj Jedrzejak <mikolajj@op.pl> + unicode.org tables * http://www.unicode.org Unicode Homepage * http://www.mikkom.pl Mikolaj Jedrzejak Homepage * * Reverse CRC adapted from "Reversing CRC � Theory and Practice" * HU Berlin Public Report * Martin Stigge, Henryk Plotz, Wolf Muller, Jens-Peter Redlich * * Official ZIP file format: http://www.pkware.com/appnote.txt * * @access public */'OMzip/OMcrc32.php''OMzip/ConvertCharset.class.php' ); /** * Creates and sends a ZIP on the fly, with no compression (just great for Jpeg/Gif/Movies) * VERY little RAM consumption, as the files never get loaded in RAM * The download starts almost immediately, as the ZIP is not created before sending * * @param name name to give to the ZIP file * @param array array of files to include * * @return integer the size of the zip in bytes * * @access public */'Content-length: '/** * Size of compressed data * * @var integer $datalen *//** * Central directory * * @var array $ctrl_dir *//** * End of central directory record * * @var string $eof_ctrl_dir */"\x50\x4b\x05\x06\x00\x00\x00\x00"; /** * Constructor : send ZIP headers * * @param string archive name * @param integer actually send the data ? * * @access private */"archive.zip"// If you're having a problem with a file download script not working with IE // if you call session_start() before sending the file, then try adding a // session_cache_limiter() call before session_start(). "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'); "Content-type: application/zip""Content-disposition: attachment; filename=\"$name\""/** * Converts an Unix timestamp to a four byte DOS date and time format (date * in high two bytes, time in low two bytes allowing magnitude comparison). * * @param integer the current Unix timestamp * * @return integer the current date in a four byte DOS format * * @access private */'year''year''mon''mday''hours''minutes''seconds'] = 0; } // end if 'year''mon''mday''hours''minutes''seconds'] >> 1); } // end of the 'unix2DosTime()' method /** * Sends a file to stdout, using output control, megabyte per megabyte. * Useful when readfile or passthru corrupt data, and supposed to be more efficient, but * consumes PHP execution time. * * @param string file path * * @return boolean success * * @access private */// how many bytes per chunk $buffer = '''rb'/** * Adds file to archive * * @param filename content file to add * @param string name of the file in the archive (may contains the path) * @param boolean whether or not to compress the data CAUTION: file must fit in RAM if "true" ! * @param integer the current timestamp * * @return boolean success of operations * * @access public */'./', '''\\', '/', $name)) , "CP1252", "CP437"'./', '''\\', '/''\x''\x''\x''\x''$hexdtime = "''";'); $fr1 = "\x50\x4b\x03\x04"; $fr1 .= "\x14\x00"; // ver needed to extract $fr1 .= "\x00\x00"; // gen purpose bit flag "\x08\x00"; // compression method "\x00\x00"; // compression method // last mod time and date // "local file header" segment // fix crc bug // crc32 that reads byte per byte the file 'V', $crc); // crc32 'V'// compressed filesize 'V'// uncompressed filesize 'v'// length of filename 'v', 0); // extra field length // send this ! // "file data" segment // now add to central directory record $cdrec ="\x50\x4b\x01\x02"; $cdrec .= "\x00\x00"; // version made by $cdrec .= "\x14\x00"; // version needed to extract $cdrec .= "\x00\x00"; // gen purpose bit flag "\x08\x00"; // compression method "\x00\x00"; // compression method // last mod time & date 'V', $crc); // crc32 'V'// compressed filesize 'V'// uncompressed filesize 'v'// length of filename 'v', 0 ); // extra field length 'v', 0 ); // file comment length 'v', 0 ); // disk number start 'v', 0 ); // internal file attributes 'V', 32 ); // external file attributes - 'archive' bit set 'V'// optional extra field, file comment goes here // save to central directory // end of the 'addFile()' method /** * Dumps out end of ZIP * * @access public */'''v'// total # of entries "on this disk" 'v'// total # of entries overall 'V'// size of central dir 'V', $this -> datalen) . // offset to start of central dir "\x00\x00"; // .zip file comment length // end of the 'file()' method } // end of the 'zipfile' class