Home > Article > Backend Development > PHP packaging program (online decompression and online packaging and downloading source code) (1/8)_PHP tutorial
PHP packaging program (online decompression and online packaging and downloading source code) This program supports file downloading, decompression and online compression, so we will check the online decompression and online packaging and downloading functions with examples.
php tutorial packaging program (online decompression and online packaging and downloading source code)
This program supports file downloading, decompression and online compression, so we can check the online decompression and online packaging and downloading functions with examples.
*/
//phpzip.class.php
class phpzip{
var $datasec, $ctrl_dir = array();
var $eof_ctrl_dir = "x50x4bx05x06x00x00x00x00";
var $old_offset = 0; var $dirs = array(".");
function get_list($zip_name) {
$zip = @fopen($zip_name, 'rb');
if(!$ zip) return(0);
$centd = $this->readcentraldir($zip,$zip_name);
@rewind($zip);
@fseek($zip, $ centd['offset']);
for ($i=0; $i<$centd['entries']; $i++)
{
$header = $this-> readcentralfileheaders($zip);
$header['index'] = $i;$info['filename'] = $header['filename'];
$info['stored_filename'] = $header[ 'stored_filename'];
$info['size'] = $header['size'];$info['compressed_size']=$header['compressed_size'];
$info['crc'] = strtoupper(dechex( $header['crc'] ));
$info['mtime'] = $header['mtime']; $info['comment'] = $header['comment'];
$info['folder'] = ($header['external']==0x41ff0010||$header['external']==16)?1:0;
$info['index'] = $header['index'];$info['status'] = $header['status'];
$ret[]=$info; unset($header);
}
return $ret;
}
function add($files,$compact) {
if(!is_array($files[0])) $files=array($files);
for($i=0;$files[$i];$i++){
$fn = $files[$i];
if(!in_array(dirname($fn[0]),$this ->dirs))
$this->add_dir(dirname($fn[0]));
if(basename($fn[0]))
$ret[basename($fn [0])]=$this->add_file($fn[1],$fn[0],$compact);
}
return $ret;
}
1 2 3 4 5 6 7 8