php关于zip的应用
php关于zip的使用
/** * * 创建压缩包 * @param array $arr 需要压缩的文件部分路径和文件名,形如 array( * '/file/upload/1.php', * '/file/upload/2011/1.jpg', * ) * * @return string 压缩包的部分路径和文件名,形如/file/uplaod/zip/123.zip */ public static function zip($arr) { //首先我建立一个目录 $save_path = '/file/upload/zip' . Dat::getHourPath(); $path = APPLICATION_PATH . '/destoon' . $save_path; Sys::createDir($path); $zipname = strval(time()) . mt_rand(100000, 999999) . '.zip'; $zip_fullname = $path . '/' . $zipname; $zip_obj = new ZipArchive(); if ($zip_obj->open($zip_fullname, ZIPARCHIVE::CREATE) !== true) { return false; } foreach ($arr as $value) { // $zip->addFile($path, mb_convert_encoding ( basename($path), 'GBK' ,'UTF-8')); $zip_obj->addFile( APPLICATION_PATH . '/destoon' . $value, basename($value) ); } $zip_obj->close(); return $save_path . '/' . $zipname; } /** * 解压缩 * * @param string $zipname 压缩包的部分路径和文件名,形如'/file/upload/1.zip' * @param string $path 解压后的文件夹全路径 * * @return array 解压后的文件数组,部分路径和文件名,形如array( * '/file/1.php', * '/file/12.png', * ) */ public static function unzip($zipname , $path='') { if (!$path ) { $path = '/file/tempzip_folder/' . strval(time()) . mt_rand(100000, 999999); $newpath = APPLICATION_PATH . '/destoon' . $path; } else { $newpath = $path; $path = preg_replace('#^.+/destoon(.+)$#', '$1', $newpath); } Sys::createDir($newpath); $filename = APPLICATION_PATH . '/destoon' . $zipname; //第一件事是解压 $zip = new ZipArchive(); $arr = array(); if ($zip->open($filename) === true) { $zip->extractTo($newpath); $zip->close(); $temp = scandir($newpath); foreach ($temp as $value) { if ($value != '.' && $value != '..') { $arr[] = $path . '/' . basename($value); } } } return $arr; }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to set the PATH environment variable in Linux systems In Linux systems, the PATH environment variable is used to specify the path where the system searches for executable files on the command line. Correctly setting the PATH environment variable allows us to execute system commands and custom commands at any location. This article will introduce how to set the PATH environment variable in a Linux system and provide detailed code examples. View the current PATH environment variable. Execute the following command in the terminal to view the current PATH environment variable: echo$P

Compressing HTML files into ZIP can improve page loading speed. Methods include: using online tools (such as FileOptimizer, TinyPNG) using command line tools (such as gzip, 7-zip) using Node.js scripts (using the zlib module)

The zip command is a very useful compression tool in Linux systems. By using the zip command, you can easily compress files and directories into a zip file and save storage space and facilitate transfer. The basic syntax of the zip command is "zip [options] [compressed file name] [file or directory to be compressed]".

1. The compressed folder is a zip file [root@cgls]#zip-rmydata.zipmydata2. Unzip mydata.zip into the mydatabak directory [root@cgls]#unzipmydata.zip-dmydatabak3.mydata01 folder and mydata02.txt are compressed into mydata.zip[root@cgls]#zipmydata.zipmydata01mydata02.txt4. Decompress the mydata.zip file directly [root@cgls]#unzipmydata.zip5. View myd

Method to set the path environment variable: 1. Windows system, open "System Properties", click the "Properties" option, click "Advanced System Settings", in the "System Properties" window, select the "Advanced" tab, and then click "Environment Variables" " button, find and click "Path" to edit and save; 2. For Linux systems, open the terminal, open your bash configuration file, add "export PATH=$PATH: file path" at the end of the file and save it; 3. For MacOS system, the operation is the same as above.

7z and zip are both lossless compressions. 7z is a mainstream and efficient compression format with a very high compression ratio; the ZIP file format is a file format for data compression and document storage. 7z has a higher compression ratio, followed by zip; the zip format is more common and has a wide range of technologies, and the windows operating system supports the zip format by default.

Compressing files is a common operation that can save disk space and network transmission time, and Java provides the Zip function for file compression. This article will show how to use the Zip function in Java for file compression through a detailed introduction and example demonstration. 1. Introduction to the Zip function The Zip function is a compression and packaging tool library provided in Java. This function can be used to compress files or folders into a Zip format file. ZipOutputStr is mainly used in the Zip function

How to correctly set the PATH environment variable in Linux In the Linux operating system, environment variables are one of the important mechanisms used to store system-level configuration information. Among them, the PATH environment variable is used to specify the directories in which the system searches for executable files. Correctly setting the PATH environment variable is a key step to ensure the normal operation of the system. This article will introduce how to correctly set the PATH environment variable in Linux and provide specific code examples. 1. Check the current PATH environment variable and enter the following command in the terminal
