Skip to content

Commit 4568a0b

Browse files
committed
Add utility function to download files
Signed-off-by: Riddhesh Sanghvi <[email protected]>
1 parent 4c713b2 commit 4568a0b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

php/utils.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,22 @@ function get_config_value( $key, $default = null ) {
16451645
return empty( $existing_config[ $key ] ) ? $default : $existing_config[ $key ];
16461646
}
16471647

1648+
/**
1649+
* Function to download file to a path.
1650+
*
1651+
* @param string $path Path to download the file on.
1652+
* @param string $download_url Url to download the file from.
1653+
*/
1654+
function download( $path, $download_url ) {
1655+
1656+
$headers = array();
1657+
$options = array(
1658+
'timeout' => 1200, // 20 minutes ought to be enough for everybody.
1659+
'filename' => $path,
1660+
);
1661+
http_request( 'GET', $download_url, null, $headers, $options );
1662+
}
1663+
16481664
/**
16491665
* Random name generator.
16501666
*

0 commit comments

Comments
 (0)