Torrent::file_get_contents PHP Method

file_get_contents() public static method

Helper to get (distant) file content
public static file_get_contents ( $file, $timeout = self::timeout, $offset = null, $length = null ) : string | boolean
return string | boolean file content or false if error
    public static function file_get_contents($file, $timeout = self::timeout, $offset = null, $length = null)
    {
        if (is_file($file) || ini_get('allow_url_fopen')) {
            $context = !is_file($file) && $timeout ? stream_context_create(array('http' => array('timeout' => $timeout))) : null;
            return !is_null($offset) ? $length ? @file_get_contents($file, false, $context, $offset, $length) : @file_get_contents($file, false, $context, $offset) : @file_get_contents($file, false, $context);
        } elseif (!function_exists('curl_init')) {
            return self::set_error(new Exception('Install CURL or enable "allow_url_fopen"'));
        }
        $handle = curl_init($file);
        if ($timeout) {
            curl_setopt($handle, CURLOPT_TIMEOUT, $timeout);
        }
        if ($offset || $length) {
            curl_setopt($handle, CURLOPT_RANGE, $offset . '-' . ($length ? $offset + $length - 1 : null));
        }
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
        $content = curl_exec($handle);
        $size = curl_getinfo($handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
        curl_close($handle);
        return $offset && $size == -1 || $length && $length != $size ? $length ? substr($content, $offset, $length) : substr($content, $offset) : $content;
    }