1 install.core.inc | install_retrieve_file($uri, $destination) |
Attempts to get a file using a HTTP request and to store it locally.
Parameters
string $uri: The URI of the file to grab.
string $destination: Stream wrapper URI specifying where the file should be placed. If a directory path is provided, the file is saved into that directory under its original name. If the path contains a filename as well, that one will be used instead.
Return value
bool: TRUE on success, FALSE on failure.
File
- core/
includes/ install.core.inc, line 1524 - API functions for installing Backdrop.
Code
function install_retrieve_file($uri, $destination) {
$parsed_url = parse_url($uri);
if (is_dir(backdrop_realpath($destination))) {
// Prevent URIs with triple slashes when gluing parts together.
$path = str_replace('///', '//', "$destination/") . backdrop_basename($parsed_url['path']);
}
else {
$path = $destination;
}
$response = backdrop_http_request($uri, array('timeout' => 5));
if ($response->code != 200) {
return FALSE;
}
$data = $response->data;
if (empty($data)) {
return FALSE;
}
return file_put_contents($path, $data) !== FALSE;
}