问题
How can I extract .zip (100%), using PHP?
回答1:
If you have zziplib installed, you can use this code:
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->extractTo('/my/destination/dir/');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
Make sure the user executing php (usually nobody, apache or httpd) have writing privileges on destination dir.
回答2:
Use the Zip API. The algorithm for this is:
- Open file with zip_open
- Read directory entry with zip_read; if false goto step 8
- Get the name with zip_entry_name
- Open the entry with zip_entry_open
- Get the data with zip_entry_read, and store how & where you want
- Close the entry with zip_entry_close
- Goto step 2
- Close file with zip_close
Hope this helps,
Phil Lello
来源:https://stackoverflow.com/questions/5653130/extract-zip-files-using-php