src/Uploadcare/Uploader.php
private function fromUrlNew($url, $options = array())
    {
        $default_options = array(
            'store' => 'auto',
            'filename' => null,
            'check_status' => true,
            'timeout' => 1,
            'max_attempts' => 5,
        );
        $params = array_merge($default_options, $options);
        $check_status = $params['check_status'];
        $timeout = $params['timeout'];
        $max_attempts = $params['max_attempts'];

        $requestData = array(
            '_' => time(),
            'source_url' => $url,
            'pub_key' => $this->api->getPublicKey(),
            'store' => $params['store'],
        );
        if ($params['filename']) {
            $requestData['filename'] = $params['filename'];
        }

        $ch = $this->__initRequest('from_url', $requestData);
        $this->__setHeaders($ch);

        $data = $this->__runRequest($ch);
        $token = $data->token;

        if ($check_status) {
            $success = false;
            $attempts = 0;
            while (!$success) {
                $data = $this->status($token);
                if ($data->status == 'success') {
                    $success = true;
                }
                if ($data->status == 'error') {
                    throw new \Exception('Upload is not successful: ' . $data->error);
                }
                if ($attempts == $max_attempts && $data->status != 'success') {
                    throw new \Exception('Max attempts reached, upload is not successful');
                }
                sleep($timeout);
                $attempts++;
            }
        } else {
            return $token;
        }
        $uuid = $data->uuid;

        return new File($uuid, $this->api);
    }
private function fromUrlNew($url, $options = array())
    {
        $default_options = array(
            'store' => 'auto',
            'filename' => null,
            'check_status' => true,
            'timeout' => 1,
            'max_attempts' => 5,
        );
        $params = array_merge($default_options, $options);
        $check_status = $params['check_status'];
        $timeout = $params['timeout'];
        $max_attempts = $params['max_attempts'];

        $requestData = array(
            '_' => time(),
            'source_url' => $url,
            'pub_key' => $this->api->getPublicKey(),
            'store' => $params['store'],
        );
        if ($params['filename']) {
            $requestData['filename'] = $params['filename'];
        }

        $ch = $this->__initRequest('from_url', $requestData);
        $this->__setHeaders($ch);

        $data = $this->__runRequest($ch);
        $token = $data->token;

        if ($check_status) {
            $success = false;
            $attempts = 0;
            while (!$success) {
                $data = $this->status($token);
                if ($data->status == 'success') {
                    $success = true;
                }
                if ($data->status == 'error') {
                    throw new \Exception('Upload is not successful: ' . $data->error);
                }
                if ($attempts == $max_attempts && $data->status != 'success') {
                    throw new \Exception('Max attempts reached, upload is not successful');
                }
                sleep($timeout);
                $attempts++;
            }
        } else {
            return $token;
        }
        $uuid = $data->uuid;

        return new File($uuid, $this->api);
    }
Upload file from a URL and get File instance

@param string $url A URL of file to be uploaded.
@param array $options Optional dictionary with additional params. Available keys are following:
'store' - can be true, false or 'auto'. This flag indicates should file be stored automatically after upload.
'filename' - should be a string, Sets explicitly file name of uploaded file.
'check_status' - Wait till upload is complete
'timeout' - Wait number of seconds between status checks
'max_attempts' - Check status no more than passed number of times
@throws \Exception
@return File|string