-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changing the
save_remote_image
to use HttpClient
- Loading branch information
Showing
1 changed file
with
15 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,14 @@ | |
* @author Arman Ag. <[email protected]> | ||
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) | ||
* @link http://quantum.softberg.org/ | ||
* @since 2.9.0 | ||
* @since 2.9.5 | ||
*/ | ||
|
||
use Quantum\Libraries\Storage\FileSystem; | ||
use Quantum\Libraries\Curl\HttpClient; | ||
use Quantum\Exceptions\LangException; | ||
use Quantum\Exceptions\HttpException; | ||
use Quantum\Exceptions\AppException; | ||
use Quantum\Exceptions\DiException; | ||
use Quantum\Di\Di; | ||
|
||
|
@@ -66,15 +69,25 @@ function url_with_lang(string $lang): string | |
* @param string $imageName | ||
* @return string | ||
* @throws DiException | ||
* @throws ErrorException | ||
* @throws LangException | ||
* @throws ReflectionException | ||
* @throws AppException | ||
* @throws HttpException | ||
*/ | ||
function save_remote_image(string $imageUrl, string $userDirectory, string $imageName): string | ||
{ | ||
$fs = Di::get(FileSystem::class); | ||
|
||
$imageName = slugify($imageName) . '.jpg'; | ||
|
||
$fs->put(uploads_dir() . DS . $userDirectory . DS . $imageName, $fs->get($imageUrl)); | ||
$httpClient = new HttpClient(); | ||
$httpClient->createRequest($imageUrl); | ||
$httpClient->setMethod('GET'); | ||
$httpClient->setOpt(CURLOPT_FOLLOWLOCATION, true); | ||
$httpClient->start(); | ||
|
||
$fs->put(uploads_dir() . DS . $userDirectory . DS . $imageName, $httpClient->getResponseBody()); | ||
|
||
return $imageName; | ||
} |