Craft\EmbeddedAssetsService::_readExternalFile PHP Method

_readExternalFile() private method

Reads in data from an external link.
private _readExternalFile ( $url ) : boolean | mixed | string
$url
return boolean | mixed | string
    private function _readExternalFile($url)
    {
        if (function_exists('curl_init')) {
            EmbeddedAssetsPlugin::log("Reading file with `curl`");
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_AUTOREFERER, true);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            $data = curl_exec($ch);
            $error = curl_error($ch);
            if (!empty($error)) {
                EmbeddedAssetsPlugin::log("Error reading file (\"{$error}\")", LogLevel::Error);
                $data = false;
            }
            curl_close($ch);
            return $data;
        }
        $allowUrlFopen = preg_match('/1|yes|on|true/i', ini_get('allow_url_fopen'));
        if ($allowUrlFopen) {
            EmbeddedAssetsPlugin::log("Reading file with `file_get_contents`");
            return @file_get_contents($url);
        }
        return false;
    }