You are here

function hackedProjectWebFilesDownloader::file_get in Hacked! 7.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 includes/hackedProjectWebFilesDownloader.inc
Download the remote files to the local filesystem.

File

includes/hackedProjectWebFilesDownloader.inc, line 71

Class

hackedProjectWebFilesDownloader
Downloads a project using a standard Drupal method.

Code

function file_get($url) {
  $parsed_url = parse_url($url);
  $remote_schemes = array(
    '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_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, FILE_EXISTS_REPLACE);
}