You are here

function hackedProjectWebFilesDownloader::file_get in Hacked! 8.2

Copies a file from $url to the temporary directory for updates.

If the file has already been downloaded, returns the the local path.

Parameters

$url: The URL of the file on the server.

Return value

string Path to local file.

1 call to hackedProjectWebFilesDownloader::file_get()
hackedProjectWebFilesDownloader::download in src/hackedProjectWebFilesDownloader.php
Download the remote files to the local filesystem.

File

src/hackedProjectWebFilesDownloader.php, line 79

Class

hackedProjectWebFilesDownloader
Downloads a project using a standard Drupal method.

Namespace

Drupal\hacked

Code

function file_get($url) {
  $parsed_url = parse_url($url);
  $remote_schemes = [
    'http',
    'https',
    'ftp',
    'ftps',
    'smb',
    'nfs',
  ];
  if (!in_array($parsed_url['scheme'], $remote_schemes)) {

    // This is a local file, just return the path.
    return \Drupal::service('file_system')
      ->realpath($url);
  }

  // Check the cache and download the file if needed.
  $cache_directory = 'temporary://hacked-cache';
  $local = $cache_directory . '/' . basename($parsed_url['path']);
  if (!file_exists($cache_directory)) {
    mkdir($cache_directory);
  }
  return system_retrieve_file($url, $local, FALSE, FileSystemInterface::EXISTS_REPLACE);
}