-
- require_once('pclzip.lib.php');
- $zip = new PclZip("archive.zip");
- $v_list = $zip->create($_SERVER[' DOCUMENT_ROOT'] ,PCLZIP_OPT_REMOVE_PATH,
- $_SERVER['DOCUMENT_ROOT']);
- if($v_list == 0){ echo 'Exception:'.$z->errorInfo(true); }
- else { echo 'Backup successful '; }
- ?>
Copy code
Other usage examples:
-
-
//Extract to the directory extract/folder/ - $list = $archive->extract(PCLZIP_OPT_PATH, "extract/folder/");< ;/p>
//Add this directory to the compressed file. After completion, there will be a backup directory in the compressed file, and there will be these two files in the backup
- $list = $archive->create(" file.txt,image.gif",PCLZIP_OPT_ADD_PATH, "backup");
//Remove part of the path, it will become test/file.txt after completion
- $list = $ archive->add("/usr/local/user/test/file.txt",PCLZIP_OPT_REMOVE_PATH,
- "/usr/local/user");
//Add all paths Remove it. After this compressed file is created, it will only contain file.txt and image.gif, and there will be no directory.
- $list = $archive->create("data/file.txt images/image.gif" ,PCLZIP_OPT_REMOVE_ALL_PATH);
//Set the CHMOD of the decompressed file to 0777
- $list = $archive->extract(PCLZIP_OPT_SET_CHMOD, 0777);
- < ;p>//Decompress part of the file, this parameter is determined by the file name
- //The argument can use the following array
- $rule_list[0] = 'test/aaa.txt';
- $rule_list[1] = 'test/ddd.txt';
- //Or as follows, in a string, use commas to separate each file to be decompressed
- $rule_list = "test/aaa.txt,test/ddd.txt";
- $list = $archive->extract(PCLZIP_OPT_BY_NAME,$rule_list);
//Extract some files, use php’s ereg() function, and the file names are compared Successful ones will be decompressed
- $list = $archive->extract(PCLZIP_OPT_BY_EREG, "aa");
//To decompress some files, use PHP's preg_match() function formula, file names that are successfully compared will be decompressed
- $list = $archive->extract(PCLZIP_OPT_BY_PREG, "/^bb/");
- //If you don’t understand the above two functions, please first Study regular expression (Regular Expression)
//Decompress according to the index of the elements in the array, but I don’t quite understand what index is = =a
- $list = $archive->extract( PCLZIP_OPT_BY_INDEX, array('0-1','6-7'));
//Extract the contents of an archive into a string
- $list = $archive->extract (PCLZIP_OPT_BY_NAME, "data/readme.txt",
- PCLZIP_OPT_EXTRACT_AS_STRING);
//Decompress the contents of a file and output it directly (echo)
- $list = $archive->extract (PCLZIP_OPT_BY_NAME, "data/readme.txt",
- PCLZIP_OPT_EXTRACT_IN_OUTPUT);
//Add a file to a compressed file, but the file will not be compressed
- $list = $archive- >add("data/file.txt", PCLZIP_OPT_NO_COMPRESSION);
//Add a comment to this compressed file. If there is an comment originally, it will be overwritten
- $list = $ archive->create("data", PCLZIP_OPT_COMMENT, "Add a comment");
//Add a comment to this compressed file. If there is already a comment, it will be followed
- $list = $archive->add("data", PCLZIP_OPT_ADD_COMMENT, "Add a comment after
- the existing one");
//Add a comment to this compressed file, if the original If there are comments, they will be placed in front of the original comments
- $list = $archive->add("data", PCLZIP_OPT_PREPEND_COMMENT, "Add a comment before
- the existing one");
- ?>
-
Copy code
|