_unzip_file_pclzip [ WordPress Function ]
_unzip_file_pclzip ( $file, $to, $needed_dirs = array() )
| Access: |
|
| Parameters: |
|
| See: | |
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: _unzip_file_ziparchive, unzip_file, wp_filter_object_list, wp_unique_filename, _wp_footer_scripts
This function should not be called directly, use unzip_file instead. Attempts to unzip an archive using the PclZip library.
Assumes that WP_Filesystem() has already been called and set up.
Source
<?php
function _unzip_file_pclzip($file, $to, $needed_dirs = array()) {
global $wp_filesystem;
// See #15789 - PclZip uses string functions on binary data, If it's overloaded with Multibyte safe functions the results are incorrect.
if ( ini_get('mbstring.func_overload') && function_exists('mb_internal_encoding') ) {
$previous_encoding = mb_internal_encoding();
mb_internal_encoding('ISO-8859-1');
}
require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
$archive = new PclZip($file);
$archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
if ( isset($previous_encoding) )
mb_internal_encoding($previous_encoding);
// Is the archive valid?
if ( !is_array($archive_files) )
return new WP_Error('incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true));
if ( 0 == count($archive_files) )
return new WP_Error('empty_archive', __('Empty archive.'));
// Determine any children directories needed (From within the archive)
foreach ( $archive_files as $file ) {
if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Skip the OS X-created __MACOSX directory
continue;
$needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname($file['filename']) );
}
$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);
// Extract the files from the zip
foreach ( $archive_files as $file ) {
if ( $file['folder'] )
continue;
if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Don't extract the OS X-created __MACOSX directory files
continue;
if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) )
return new WP_Error('copy_failed', __('Could not copy file.'), $to . $file['filename']);
}
return true;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- plugin development - What should I pass for $needed_dirs when ...
Feb 1, 2011 ... I'm seeking to use the _unzip_file_pclzip() function contained in wp-admin/ includes/file.php. However, I'm not sure what is expected for the ...
wordpress.stackexchange.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() _unzip_file_ziparchive() _unzip_file_pclzip() copy_dir() WP_Filesystem() get_filesystem_method() request_filesystem_credentials() ...
xref.yoast.com - Fatal error: Class 'ZipArchive' not found (PHP 5.3.1) - Stack Overflow
... through to PclZip if ZipArchive is not available, or encountered an error opening the file. return _unzip_file_pclzip($file, $to, $needed_dirs); } ...
stackoverflow.com