public function actionFileUploadRemote() {
		$url = $this->request->url;

		if (!$url) {
			throw new \Exception('Need url parameter', Consts::ERROR_CODE_BAD_REQUEST);
		}

		$result = parse_url($url);

		if (!isset($result['host']) || !isset($result['path'])) {
			throw new \Exception('Not valid URL', Consts::ERROR_CODE_BAD_REQUEST);
		}

		$filename = Helper::makeSafe(basename($result['path']));

		if (!$filename) {
			throw new \Exception('Not valid URL', Consts::ERROR_CODE_BAD_REQUEST);
		}

		$source = $this->config->getCompatibleSource($this->request->source);

		Helper::downloadRemoteFile($url, $source->getRoot() . $filename);

		$file = new File($source->getRoot() . $filename);

		try {
			if (!$file->isGoodFile($source)) {
				throw new \Exception('Bad file', Consts::ERROR_CODE_FORBIDDEN);
			}

			$this->accessControl->checkPermission($this->getUserRole(), $this->action, $source->getRoot(), $file->getExtension());
		} catch (\Exception $e) {
			$file->remove();
			throw $e;
		}

		return [
			'newfilename' => $file->getName(),
			'baseurl' => $source->baseurl,
		];
	}
public function actionFileUploadRemote() {
		$url = $this->request->url;

		if (!$url) {
			throw new \Exception('Need url parameter', Consts::ERROR_CODE_BAD_REQUEST);
		}

		$result = parse_url($url);

		if (!isset($result['host']) || !isset($result['path'])) {
			throw new \Exception('Not valid URL', Consts::ERROR_CODE_BAD_REQUEST);
		}

		$filename = Helper::makeSafe(basename($result['path']));

		if (!$filename) {
			throw new \Exception('Not valid URL', Consts::ERROR_CODE_BAD_REQUEST);
		}

		$source = $this->config->getCompatibleSource($this->request->source);

		Helper::downloadRemoteFile($url, $source->getRoot() . $filename);

		$file = new File($source->getRoot() . $filename);

		try {
			if (!$file->isGoodFile($source)) {
				throw new \Exception('Bad file', Consts::ERROR_CODE_FORBIDDEN);
			}

			$this->accessControl->checkPermission($this->getUserRole(), $this->action, $source->getRoot(), $file->getExtension());
		} catch (\Exception $e) {
			$file->remove();
			throw $e;
		}

		return [
			'newfilename' => $file->getName(),
			'baseurl' => $source->baseurl,
		];
	}
public function actionFileUploadRemote ( ) { $ url = $ this -> request -> url ; if ( ! $ url ) { throw new \ Exception ( 'Need url parameter' , Consts :: ERROR_CODE_BAD_REQUEST ) ; } $ result = parse_url ( $ url ) ; if ( ! isset ( $ result [ 'host' ] ) || ! isset ( $ result [ 'path' ] ) ) { throw new \ Exception ( 'Not valid URL' , Consts :: ERROR_CODE_BAD_REQUEST ) ; } $ filename = Helper :: makeSafe ( basename ( $ result [ 'path' ] ) ) ; if ( ! $ filename ) { throw new \ Exception ( 'Not valid URL' , Consts :: ERROR_CODE_BAD_REQUEST ) ; } $ source = $ this -> config -> getCompatibleSource ( $ this -> request -> source ) ; Helper :: downloadRemoteFile ( $ url , $ source -> getRoot ( ) . $ filename ) ; $ file = new File ( $ source -> getRoot ( ) . $ filename ) ; try { if ( ! $ file -> isGoodFile ( $ source ) ) { throw new \ Exception ( 'Bad file' , Consts :: ERROR_CODE_FORBIDDEN ) ; } $ this -> accessControl -> checkPermission ( $ this -> getUserRole ( ) , $ this -> action , $ source -> getRoot ( ) , $ file -> getExtension ( ) ) ; } catch ( \ Exception $ e ) { $ file -> remove ( ) ; throw $ e ; } return [ 'newfilename' => $ file -> getName ( ) , 'baseurl' => $ source -> baseurl , ] ; }
Load remote image by URL to self host
@throws \Exception
Load remote image by URL to self host