_unzip_file_ziparchive [ WordPress Function ]
_unzip_file_ziparchive ( $file, $to, $needed_dirs = array() )
| Access: |
|
| Parameters: |
|
| See: | |
| Returns: |
|
| Defined at: |
|
This function should not be called directly, use unzip_file instead. Attempts to unzip an archive using the ZipArchive class.
Assumes that WP_Filesystem() has already been called and set up.
Source
<?php
function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) {
global $wp_filesystem;
$z = new ZipArchive();
// PHP4-compat - php4 classes can't contain constants
$zopen = $z->open($file, /* ZIPARCHIVE::CHECKCONS */ 4);
if ( true !== $zopen )
return new WP_Error('incompatible_archive', __('Incompatible Archive.'));
for ( $i = 0; $i < $z->numFiles; $i++ ) {
if ( ! $info = $z->statIndex($i) )
return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory
continue;
if ( '/' == substr($info['name'], -1) ) // directory
$needed_dirs[] = $to . untrailingslashit($info['name']);
else
$needed_dirs[] = $to . untrailingslashit(dirname($info['name']));
}
$needed_dirs = array_unique($needed_dirs);
foreach ( $needed_dirs as $dir ) {
// Check the parent folders of the folders all exist within the creation array.
if ( untrailingslashit($to) == $dir ) // Skip over the working directory, We know this exists (or will exist)
continue;
if ( strpos($dir, $to) === false ) // If the directory is not within the working directory, Skip it
continue;
$parent_folder = dirname($dir);
while ( !empty($parent_folder) && untrailingslashit($to) != $parent_folder && !in_array($parent_folder, $needed_dirs) ) {
$needed_dirs[] = $parent_folder;
$parent_folder = dirname($parent_folder);
}
}
asort($needed_dirs);
// Create those directories if need be:
foreach ( $needed_dirs as $_dir ) {
if ( ! $wp_filesystem->mkdir($_dir, FS_CHMOD_DIR) && ! $wp_filesystem->is_dir($_dir) ) // Only check to see if the Dir exists upon creation failure. Less I/O this way.
return new WP_Error('mkdir_failed', __('Could not create directory.'), $_dir);
}
unset($needed_dirs);
for ( $i = 0; $i < $z->numFiles; $i++ ) {
if ( ! $info = $z->statIndex($i) )
return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
if ( '/' == substr($info['name'], -1) ) // directory
continue;
if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Don't extract the OS X-created __MACOSX directory files
continue;
$contents = $z->getFromIndex($i);
if ( false === $contents )
return new WP_Error('extract_failed', __('Could not extract file from archive.'), $info['name']);
if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE) )
return new WP_Error('copy_failed', __('Could not copy file.'), $to . $info['name']);
}
$z->close();
return true;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- _unzip_file_ziparchive() WordPress function reference, arguments ...
This function should not be called directly, use unzip_file instead. Attempts to unzip an archive using the ZipArchive class. Assumes that WP_Filesystem() has ...
queryposts.com - Android - Unzip a folder? - Stack Overflow
... public class UnZip implements Runnable { File archive; String outputDir; public UnZip(File ziparchive, String directory) { archive = ziparchive; ...
stackoverflow.com - PHPXRef 0.7 : WordPress : Detail view of file.php
download_url() unzip_file() _unzip_file_ziparchive() _unzip_file_pclzip() copy_dir() WP_Filesystem() get_filesystem_method() request_filesystem_credentials() ...
phpxref.ftwr.co.uk - file.php - PHP Cross Reference of WordPress Source - Yoast
Jun 1, 2011 ... _unzip_file_ziparchive() _unzip_file_pclzip() copy_dir() WP_Filesystem() get_filesystem_method() request_filesystem_credentials(). Functions ...
xref.yoast.com