function apachesolr_confgen_zipfile::addDir in Apache Solr Config Generator 6
Same name and namespace in other branches
- 8 lib/apachesolr_confgen_zipfile.php \apachesolr_confgen_zipfile::addDir()
- 7 lib/apachesolr_confgen_zipfile.php \apachesolr_confgen_zipfile::addDir()
File
- lib/
apachesolr_confgen_zipfile.php, line 90 - Zip file creation class to pack Apache Solr configuration files
Class
- apachesolr_confgen_zipfile
- Zip file creation class. Makes zip files.
Code
function addDir($name) {
// adds "directory" to archive - do this before putting any files in directory!
// $name - name of directory... like this: "path/"
// ...then you can add files using add_file with names like "path/file.txt"
$name = str_replace("\\", "/", $name);
$fr = "PK\3\4";
$fr .= "\n\0";
// ver needed to extract
$fr .= "\0\0";
// gen purpose bit flag
$fr .= "\0\0";
// compression method
$fr .= "\0\0\0\0";
// last mod time and date
$fr .= pack("V", 0);
// crc32
$fr .= pack("V", 0);
//compressed filesize
$fr .= pack("V", 0);
//uncompressed filesize
$fr .= pack("v", strlen($name));
//length of pathname
$fr .= pack("v", 0);
//extra field length
$fr .= $name;
// end of "local file header" segment
// no "file data" segment for path
// "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
$this->datasec[] = $fr;
$new_offset = strlen(implode("", $this->datasec));
// ext. file attributes mirrors MS-DOS directory attr byte, detailed
// at http://support.microsoft.com/support/kb/articles/Q125/0/19.asp
// now add to central record
$cdrec = "PK\1\2";
$cdrec .= "\0\0";
// version made by
$cdrec .= "\n\0";
// version needed to extract
$cdrec .= "\0\0";
// gen purpose bit flag
$cdrec .= "\0\0";
// compression method
$cdrec .= "\0\0\0\0";
// last mod time & date
$cdrec .= pack("V", 0);
// crc32
$cdrec .= pack("V", 0);
//compressed filesize
$cdrec .= pack("V", 0);
//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
$ext = "\0\0\20\0";
$ext = "";
$cdrec .= pack("V", 16);
//external file attributes - 'directory' bit set
$cdrec .= pack("V", $this->old_offset);
//relative offset of local header
$this->old_offset = $new_offset;
$cdrec .= $name;
// optional extra field, file comment goes here
// save to array
$this->ctrl_dir[] = $cdrec;
}