If you want to use Wscript. Shell for compression, thank you. & lt ;? PHPclass & nbsp; rar {public & nbsp; $ Path; & nbsp; // file Path public & nbsp; $ Save; & nbsp; // Save Path public & nb Wscript. shell compression. thank you!
Class rar
{
Public $ Path; // file Path
Public $ Save; // Save path
Public $ Object; // Wscript. Shell Object instance
Function rar () {// Constructor
$ This-> Object = new com ("Wscript. Shell"); // instantiate a Shell Object
}
Function Release () {// decompression method
$ This-> Object-> run ("WinRAR x $ this-> Path $ this-> Save", 1, false ); // Save the file name and Path to be decompressed in Path
If ($ this-> Object = true ){
Return true;
} Else {
Return false;
}
}
Function Pressure () {// compression method
$ This-> Object-> run ("WinRAR a $ this-> Save $ this-> Path", 1, true ); // Save the compressed Path and the file name Path to be compressed
If ($ this-> Object = true ){
Return true;
} Else {
Return false;
}
}
}
$ Rar = new rar ();
$ Rar-> Path = "F:/js/test/z.rar ";
$ Rar-> Save = "F:/js/test ";
If ($ rar-> Release ()){
Die ('decompressed successfully ');
} Else {
Die ('decompression failed ');
}
?>
This code can be compressed normally.
However, it can only compress absolute paths, and it adds all directories to empty folders during compression.
For example, I compress: c: \ a \ B \ c \ k.txt
The compressed file contains many layers of folders.
-
-B
-C
-K.txt
What should I do?
The relative directory cannot be compressed.
------ Solution --------------------
You can add the following parameters to winrar, but you must be clear about the consequences.
Ep exclusion path from name
When this switch is included, the file will not contain path information when it is added to the compressed file. This may result in several results with the same name in the compressed file.
Ed does not add an empty directory
This switch indicates that the empty directory is not stored in the created compressed file. When extracting such a compressed file, RAR will create a non-empty directory based on their internal file path. Information about empty directories is lost. Non-empty directories except names (access permissions, streams, and so on .) All other attributes are lost, so this switch is used only when you do not need to retain such information.
------ Solution --------------------
$ This-> Object-> run ("WinRAR a parameter here $ this-> Save $ this-> Path", 1, true );