function install_retrieve_file

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

boolean TRUE on success, FALSE on failure.

1 call to install_retrieve_file()
install_check_translations in drupal/core/includes/install.core.inc
Checks installation requirements and reports any errors.

File

drupal/core/includes/install.core.inc, line 1585
API functions for installing Drupal.

Code

function install_retrieve_file($uri, $destination) {
  $parsed_url = parse_url($uri);
  if (is_dir(drupal_realpath($destination))) {

    // Prevent URIs with triple slashes when gluing parts together.
    $path = str_replace('///', '//', "{$destination}/") . drupal_basename($parsed_url['path']);
  }
  else {
    $path = $destination;
  }
  try {
    $request = Drupal::httpClient()
      ->get($uri, array(
      'Accept' => 'text/plain',
    ));
    $data = $request
      ->send()
      ->getBody(TRUE);
    if (empty($data)) {
      return FALSE;
    }
  } catch (RequestException $e) {
    return FALSE;
  }
  return file_put_contents($path, $data) !== FALSE;
}