Skip to content

Commit 0b2a3ca

Browse files
committed
Add utility function to extract zip archives
Signed-off-by: Riddhesh Sanghvi <[email protected]>
1 parent 4568a0b commit 0b2a3ca

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

php/utils.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,28 @@ function download( $path, $download_url ) {
16611661
http_request( 'GET', $download_url, null, $headers, $options );
16621662
}
16631663

1664+
/**
1665+
* Extract zip files.
1666+
*
1667+
* @param string $zip_file Path to the zip file.
1668+
* @param string $path_to_extract Path where zip needs to be extracted to.
1669+
*
1670+
* @return bool Success of extraction.
1671+
*/
1672+
function extract_zip( $zip_file, $path_to_extract ) {
1673+
1674+
$zip = new ZipArchive;
1675+
$res = $zip->open( $zip_file );
1676+
if ( true === $res ) {
1677+
$zip->extractTo( $path_to_extract );
1678+
$zip->close();
1679+
1680+
return true;
1681+
}
1682+
1683+
return false;
1684+
}
1685+
16641686
/**
16651687
* Random name generator.
16661688
*

0 commit comments

Comments
 (0)