function epub_unzip in Epub 7
Same name and namespace in other branches
- 8 epub.module \epub_unzip()
1 call to epub_unzip()
File
- ./
epub.module, line 170
Code
function epub_unzip($filepath, $destination) {
$destination .= '/';
$extracted = array();
if ($z = zip_open($filepath)) {
while ($entry = zip_read($z)) {
if (zip_entry_open($z, $entry, 'r') && ($zip_entry_filesize = zip_entry_filesize($entry))) {
$entry_name = zip_entry_name($entry);
$data = zip_entry_read($entry, $zip_entry_filesize);
$filepath = $destination . $entry_name;
$parent_dir = dirname($filepath);
if (!file_exists($parent_dir)) {
file_prepare_directory($parent_dir, FILE_CREATE_DIRECTORY);
}
if ($filepath = file_unmanaged_save_data($data, $filepath, FILE_EXISTS_REPLACE)) {
$file = new StdClass();
$file->filename = $entry_name;
$file->filemime = file_get_mimetype($filepath);
$file->filesize = filesize($filepath);
$extracted[] = $file;
}
zip_entry_close($entry);
}
}
zip_close($z);
}
return $extracted;
}