I accidentally saw this function code on the Internet and haven't tried it yet. I will try it later. Add to favorites. Instructions for use:
// Load the function
Include_once ('phpcodezip. php ');
// Create an encrypted file (the Directory of the PHP file to be encrypted by sourceDir and the Directory of the files encrypted by targetDir)
$ Encryption = new PhoCodeZip ('sourcedir', 'targetdir ');
// Execute row encryption
$ Encryption-> zip ();
PhpCodeZip. php source code download
PhpCodeZip.rar
PhpCodeZip. php source code content
The code is as follows:
/*
* @ License: MIT & GPL
*/
Class PhpCodeZip {
// Source information to be encrypted
Var $ sourceDir = '.';
// Encrypt the stored data
Var $ targetDir = 'tmp ';
// Whether the data is encrypted
Var $ bcompiler = true;
// Whether to remove the blank trim to parse the rows
Var $ strip = true;
// Route records of the source data records
Var $ sourcefilePaths = array ();
// Destination information records
Var $ targetPaths = array ();
// Enter the data size before encryption
Var $ sizeBeforeZip = null;
// Encrypt the encrypted data size.
Var $ sizeAfterZip = null;
// Extract the output of the rows
Var $ newline = '';
/**
* Create a constructor
*
* @ Param string $ sourceDir Origin Resource
* @ Param string $ targetDir target resource
* @ Param boolean $ whether bcompiler is encrypted
* @ Param boolean $ whether strip removes the blank limit to parse the limit row
* @ Return boolean
*/
Public function PhpCodeZip ($ sourceDir = '.', $ targetDir = 'tmp ', $ bcompiler = true, $ strip = true ){
// Configure the initial changes
$ This-> sourceDir = $ sourceDir;
$ This-> targetDir = $ targetDir;
$ This-> bcompiler = $ bcompiler;
// Check whether the source data exists
If (! Is_dir ($ this-> sourceDir )){
Die ('specifies the source resource quota'. $ this-> sourceDir. 'does not exist. please reset it ');
} Else {
// If the specified destination resource exists, cut down the duplicate shard.
If (is_dir ($ this-> targetDir )){
Echo '[initialize destination information]'. $ this-> newline. $ this-> newline;
$ This-> cleanDir ($ this-> targetDir, true );
}
// Establish the same object information as the source data structure
Mkdir ($ this-> targetDir, 0777 );
$ Dir_paths = $ this-> getPaths ($ this-> sourceDir, '*', GLOB_ONLYDIR );
Foreach ($ dir_paths as $ key => $ path ){
$ Path = explode ('/', $ path );
$ Path [0] = $ this-> targetDir;
Echo '=>'. join ('/', $ path). $ this-> newline;
Mkdir (join ('/', $ path), 0777 );
}
// Retrieve the inventory statement of the source data
$ This-> sourcefilePaths = $ this-> getPaths ($ this-> sourceDir ,'*');
// Configure the checklist for the corresponding destination
Foreach ($ this-> sourcefilePaths as $ key => $ path ){
// Set the target data warehouse case
$ Path = explode ('/', $ path );
$ Path [0] = $ this-> targetDir;
$ This-> targetPaths [$ key] = join ('/', $ path );
}
// Record the data size before the row
$ This-> sizeBeforeZip = $ this-> getSizeUnit ($ this-> getDirSize ($ this-> sourceDir), 2 );
Echo $ this-> newline. $ this-> newline;
}
}
/**
* Perform encryption.
* @ Return boolean
*/
Public function zip (){
$ This-> newline = '';
Echo '[initial encryption program] (item size:'. $ this-> sizeBeforeZip. ')'. $ this-> newline. $ this-> newline;
// Prepare the source region in the future
Foreach ($ this-> sourcefilePaths as $ key => $ path ){
If (is_file ($ path )){
// Obtain the case information
$ PathInfo = pathInfo ($ path );
Echo 'fetch source response: '. $ path. $ this-> newline;
// Obtain the content after the specified volume
Echo '=> remove blank solution ..........';
If ($ this-> strip & $ pathInfo ['extension'] = 'php '){
$ FileAterZip = php_strip_whitespace ($ path );
} Else {
$ FileAterZip = file_get_contents ($ path );
}
Echo 'finished Line'. $ this-> newline;
// Retrieve the internal volume after the upload to the destination location
$ Fp = fopen ($ this-> targetPaths [$ key], 'W + ');
Echo '=> login into destination ..........';
Fwrite ($ fp, $ fileAterZip );
Fclose ($ fp );
Echo 'finished Line'. $ this-> newline;
// If you select encryption
If ($ this-> bcompiler & $ pathInfo ['extension'] = 'php '){
Echo '=> encrypt the original token ..........';
// Original Shard
$ Fh = fopen ($ this-> targetPaths [$ key]. 'encryption. php', "w ");
Bcompiler_write_header ($ fh );
Bcompiler_write_file ($ fh, $ this-> targetPaths [$ key]);
Bcompiler_write_footer ($ fh );
Fclose ($ fh );
// Remove unencrypted original tokens
Unlink ($ this-> targetPaths [$ key]);
// Rename the encrypted case
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.