Stažení vzdáleného souboru pomocí  cURL
@param $url URL vzdáleného souboru
@param $path Kam stažený soubor uložit?
@param bool $stream
188350
public static function downloadFile($url, $path, $stream = TRUE) {

        $curl = curl_init($url);

        if(!$stream) {

            curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
            file_put_contents($path, curl_exec($curl));
        }
        else {

            $fp = fopen($path, 'w');

            curl_setopt($curl, CURLOPT_FILE, $fp);
            curl_exec($curl);
            fclose($fp);
        }

        curl_close($curl);
    }
798288
private function setOutputFile(int $stream, string $path, bool $append)
    {
        if (!is_writable($path)) {
            throw new \InvalidArgumentException(
                "invalid value provided for 'path'; ".
                "'$path' is not a writable file"
            );
        }
        $this->spec[$stream] = ["file", $path, $append === true ? "a" : "w"];
    }
200568
public function readStream($path)
    {
        $location = $this->applyPathPrefix($path);

        try {
            $stream = $this->share->read($location);
        } catch (NotFoundException $e) {
            return false;
        }

        return compact('path', 'stream');
    }
624233
public function unlink($path)
    {
        $stream = $this->createStream($path);

        try {
            $stream->open($this->createStreamMode('w+'));
        } catch (\RuntimeException $e) {
            return false;
        }

        return $stream->unlink();
    }
169643
public function downloadStream($path)
    {
        $url = $this->getDownloadUrlForFile($path);
        $input = $this->getStreamForUrl($url);

        $output = fopen('php://temp', 'w+');
        if ($output === false) {
            throw new OneDriveClientException('Error when saving the downloaded file');
        }

        while (!$input->eof()) {
            $writeResult = fwrite($output, $input->read(8192));
            if ($writeResult === false) {
                throw new OneDriveClientException('Error when saving the downloaded file');
            }
        }

        $input->close();

        rewind($output);

        return $output;
    }
632214
public function postStream($url, $data, $files = [], $header = [])
    {
        if (!is_array($files)) {
            $file = $files;
            $files = ['file' => $file];
        }
        foreach ($files as $key => $item) {
            if ($streamData = FileUtil::readStream($item)) {
                $data["{$key}\";filename=\"{$key}"] = $streamData;
            }
        }
        return $this->exec($url, $data, 'post', $header);
    }
953670
protected function createStreamWrapper($path)
    {
        if ($this->streamWrapper === null) {
            $explodedPath = explode(':', $path, 2);
            $scheme = array_shift($explodedPath);
            $registeredStreamWrappers = self::$registeredStreamWrappers;
            $registeredStreamWrapperForScheme = $registeredStreamWrappers[$scheme];
            $this->streamWrapper = new $registeredStreamWrapperForScheme();
        }
    }
994089
private function putFile($path, $data)
    {
        $info = false;
        $url = parse_url($path);

        $fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 5);
        if (!$fp) {
            return false;
        }

        $buffer = '';
        $b = "\r\n";

        stream_set_blocking($fp, true);
        stream_set_timeout($fp, 30, 200000);

        $out = 'PUT '.$url['path'].' HTTP/1.1'.$b;
        $out .= 'Host: '.$url['host'].$b;
        $out .= 'Content-Length: '.Util\Size::fromContent($data).$b.$b;
        $out .= $data;
        $out .= $b.$b;
        fwrite($fp, $out);
        fflush($fp);

        stream_set_blocking($fp, true);
        stream_set_timeout($fp, 30, 200000);

        while (!feof($fp) && !$info['timed_out']) {
            $info = stream_get_meta_data($fp);
            $buffer .= fgets($fp, 128);
        }
        fclose($fp);

        return true;
    }
530592
public function streaming_write_callback($curl_handle, $data)
    {
        $length        = strlen($data);
        $written_total = 0;
        $written_last  = 0;

        while ($written_total < $length) {
            $written_last = fwrite($this->write_stream, substr($data, $written_total));

            if ($written_last === false) {
                return $written_total;
            }

            $written_total += $written_last;
        }

        // Execute callback function
        if ($this->registered_streaming_write_callback) {
            call_user_func($this->registered_streaming_write_callback, $curl_handle, $written_total);
        }

        return $written_total;
    }
818762
public static function init($path, $url = '/')
  {
    self::$path = rtrim(realpath($path), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    self::$url = $url;
    self::$router = new Router();

    self::$page->onInit();
    self::$page->onPost();
    self::$page->beforeRender();
    print self::$page->render();
    self::$page->afterRender();
  }
886264
public function readStream($path)
    {
        try {
            $stream = fopen(cloudinary_url($path), 'r');
        } catch (Exception $e) {
            return false;
        }

        return compact('stream', 'path');
    }
402245
public function readStream($path)
    {
        if ( ! $data = $this->read($path)) {
            return false;
        }

        $stream = \fopen('php://temp', 'w+b');
        \fwrite($stream, $data['contents']);
        \rewind($stream);
        $data['stream'] = $stream;
        unset($data['contents']);

        return $data;
    }
376664
public function read($path)
    {
        $location = $this->applyPathPrefix($path);

        try {
            $stream = $this->share->read($location);
        } catch (NotFoundException $e) {
            return false;
        }

        $contents = stream_get_contents($stream);

        if ($contents === false) {
            return false;
        }

        fclose($stream);

        return compact('path', 'contents');
    }
1102805
public function stream_open($url, $mode, $options, &$openedPath)
  {
    $partition = self::getPartition($url);
    $path = self::getRelativePath($url);

    $this->_filePointer = $partition->fileOpen(
      $path, $mode, $options, $this->_fileEntity
    );

    $result = !!$this->_filePointer;
    if ($result && ($options & STREAM_USE_PATH)) {
      $openedPath = $path;
    }
    return $result;
  }
516408
public function writeStream($path, $resource, Config $config)
    {
        $this->recursiveCreateDir(Util::dirname($path));

        $location = $this->applyPathPrefix($path);
        $stream = $this->share->write($location);

        stream_copy_to_stream($resource, $stream);

        if (!fclose($stream)) {
            return false;
        }

        return compact('path');
    }
1067705
public function url_stat($path, $flags)
    {
        $stream = $this->createStream($path);

        try {
            $stream->open($this->createStreamMode('r+'));
        } catch (\RuntimeException $e) {
        }

        return $stream->stat();
    }
772015
public static function postRequest($url, $data)
    {
        $url = str_replace("&amp;", "&", urldecode(trim($url)));

        $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data)));
        $context = stream_context_create($options);

        try {
            $data = @file_get_contents($url, false, $context);
            return $data;
        } catch (\Exception $e) {
            return false;
        }
    }