Server : LiteSpeed System : Linux server335.web-hosting.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64 User : cardxfeb ( 2452) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/cardxfeb/public_html/vendor/spatie/laravel-medialibrary/src/Downloaders/ |
<?php
namespace Spatie\MediaLibrary\Downloaders;
use Spatie\MediaLibrary\MediaCollections\Exceptions\UnreachableUrl;
class DefaultDownloader implements Downloader
{
public function getTempFile(string $url): string
{
$context = stream_context_create([
"http" => [
"header" => "User-Agent: Spatie MediaLibrary",
],
]);
if (! $stream = @fopen($url, 'r', false, $context)) {
throw UnreachableUrl::create($url);
}
$temporaryFile = tempnam(sys_get_temp_dir(), 'media-library');
file_put_contents($temporaryFile, $stream);
fclose($stream);
return $temporaryFile;
}
}