本文整理汇总了PHP中zipfile::old_offset方法的典型用法代码示例。如果您正苦于以下问题:PHP zipfile::old_offset方法的具体用法?PHP zipfile::old_offset怎么用?PHP zipfile::old_offset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zipfile
的用法示例。
在下文中一共展示了zipfile::old_offset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fopen
function _add($name, $file)
{
$handle = fopen($file, 'rb');
$data = fread($handle, filesize($file));
$name = str_replace("\\", "/", $name);
//$name = str_replace("\\", "\\\\", $name);
$fr = "PK";
$fr .= "";
// ver needed to extract
$fr .= "";
// gen purpose bit flag
$fr .= "";
// compression method
$fr .= "";
// last mod time and date
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = gzcompress($data);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
// fix crc bug
$c_len = strlen($zdata);
$fr .= pack("V", $crc);
// crc32
$fr .= pack("V", $c_len);
//compressed filesize
$fr .= pack("V", $unc_len);
//uncompressed filesize
$fr .= pack("v", strlen($name));
//length of filename
$fr .= pack("v", 0);
//extra field length
$fr .= $name;
// end of "local file header" segment
// "file data" segment
$fr .= $zdata;
// "data descriptor" segment (optional but necessary if archive is not served as file)
$fr .= pack("V", $crc);
//crc32
$fr .= pack("V", $c_len);
//compressed filesize
$fr .= pack("V", $unc_len);
//uncompressed filesize
// add this entry to array
self::$datasec[] = $fr;
$new_offset = strlen(implode("", self::$datasec));
// now add to central directory record
$cdrec = "PK";
$cdrec .= "";
// version made by
$cdrec .= "";
// version needed to extract
$cdrec .= "";
// gen purpose bit flag
$cdrec .= "";
// compression method
$cdrec .= "";
// last mod time & date
$cdrec .= pack("V", $crc);
// crc32
$cdrec .= pack("V", $c_len);
//compressed filesize
$cdrec .= pack("V", $unc_len);
//uncompressed filesize
$cdrec .= pack("v", strlen($name));
//length of filename
$cdrec .= pack("v", 0);
//extra field length
$cdrec .= pack("v", 0);
//file comment length
$cdrec .= pack("v", 0);
//disk number start
$cdrec .= pack("v", 0);
//internal file attributes
$cdrec .= pack("V", 32);
//external file attributes - 'archive' bit set
$cdrec .= pack("V", self::$old_offset);
//relative offset of local header
self::$old_offset = $new_offset;
$cdrec .= $name;
// optional extra field, file comment goes here
// save to central directory
self::$ctrl_dir[] = $cdrec;
}