Skip to content

Commit

Permalink
Changing the save_remote_image to use HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
live-soft committed Dec 23, 2024
1 parent 0a3a50f commit bbd7a8d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions helpers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

0 comments on commit bbd7a8d

Please sign in to comment.