unzip_file [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Unzips a specified ZIP file to a location on the Filesystem via the WordPress Filesystem Abstraction.
Assumes that WP_Filesystem() has already been called and set up. Does not extract a root-level __MACOSX directory, if present.
Attempts to increase the PHP Memory limit to 256M before uncompressing, However, The most memory required shouldn't be much larger than the Archive itself.
Source
<?php
function unzip_file($file, $to) {
global $wp_filesystem;
if ( ! $wp_filesystem || !is_object($wp_filesystem) )
return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
// Unzip can use a lot of memory, but not this much hopefully
@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
$needed_dirs = array();
$to = trailingslashit($to);
// Determine any parent dir's needed (of the upgrade directory)
if ( ! $wp_filesystem->is_dir($to) ) { //Only do parents if no children exist
$path = preg_split('![/\\\]!', untrailingslashit($to));
for ( $i = count($path); $i >= 0; $i-- ) {
if ( empty($path[$i]) )
continue;
$dir = implode('/', array_slice($path, 0, $i+1) );
if ( preg_match('!^[a-z]:$!i', $dir) ) // Skip it if it looks like a Windows Drive letter.
continue;
if ( ! $wp_filesystem->is_dir($dir) )
$needed_dirs[] = $dir;
else
break; // A folder exists, therefor, we dont need the check the levels below this
}
}
if ( class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true ) ) {
$result = _unzip_file_ziparchive($file, $to, $needed_dirs);
if ( true === $result ) {
return $result;
} elseif ( is_wp_error($result) ) {
if ( 'incompatible_archive' != $result->get_error_code() )
return $result;
}
}
// Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
return _unzip_file_pclzip($file, $to, $needed_dirs);
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/unzip file « WordPress Codex
Description. Unzip's a specified ZIP file to a location on the Filesystem via the WordPress Filesystem Abstraction.Assumes that WP_Filesystem() has already ...
codex.wordpress.org - plugin development - Anyone using unzip_file successfully? It ...
Jan 31, 2011 ... When I call the WordPress unzip_file() function below, instead of actually extracting the zip, it merely moves it into the target folder. When I trace ...
wordpress.stackexchange.com - [#MDL-17614] unzip_file function in moodlelib - Moodle Tracker
I'm fairly new to PHP programming, so I'm just tossing this out there to see what the more exprerienced folks think: During a restore of a sizable course backup ...
tracker.moodle.org - PHPXRef 0.7 : WordPress : Function Reference: unzip_file()
Function and Method Cross Reference. unzip_file(). Defined at: /wp-admin/ includes/file.php -> line 501. Referenced 1 times: ...
phpxref.ftwr.co.uk
Kullanýcý Tartýþmalarý [ wordpress.org ]
- Adam on "Returning true when it doesn't do anything?"
- Adam on "Can some one explain what I am doing wrong?"
- michael.mariart on "Can some one explain what I am doing wrong?"
- Adam on "Can some one explain what I am doing wrong?"
- Adam on "Can some one explain what I am doing wrong?"
- Nashwan Doaqan on "How Can I Use unzip_file() function in my theme ?"
- fhsm on "How to initialize WP_Filesystem object?"
- fhsm on "How to initialize WP_Filesystem object?"
- Dion Hulse (@dd32) on "How to initialize WP_Filesystem object?"
- fhsm on "How to initialize WP_Filesystem object?"