athlon1600/php-curl-file-downloader
Download remote files in PHP using cURL with a simple, lightweight wrapper. Supports saving to disk, streaming, progress callbacks, custom headers/options, redirects and timeouts—handy for CLIs or apps that need reliable file downloads.
## Getting Started
Install via Composer:
```bash
composer require vendor/package-name
The package excels at automatically guessing filenames from URLs, especially in edge cases like missing extensions. For quick testing, use the guessFilename() method:
use Vendor\Package\FilenameGuesser;
$guesser = new FilenameGuesser();
$filename = $guesser->guessFilename('https://r3---sn-vgqsrnes.googlevideo.com/videoplayback');
echo $filename; // Outputs: videoplayback.mp4 (now inferred from HTTP headers)
Key use case: Media processing pipelines (e.g., YouTube/streaming URLs) where filenames lack extensions.
guessFilename().Content-Type) for extension inference:
$guesser->setHeaders(['Content-Type' => 'video/mp4']);
$filename = $guesser->guessFilename($url);
Storage::put():
$path = $guesser->guessFilename($url);
Storage::disk('s3')->put($path, file_get_contents($url));
DownloadVideoJob::dispatch($url)->onQueue('videos');
$this->app->singleton(FilenameGuesser::class, fn() => new FilenameGuesser());
Content-Type headers. If headers are missing or incorrect (e.g., video/webm for an MP4), the guess may fail. Always validate headers in production..mp4 for unrecognized types. Override with a custom strategy:
$guesser->setDefaultExtension('webm');
?id=123) may break parsing. Use parse_url() to sanitize inputs:
$baseUrl = parse_url($url, PHP_URL_PATH);
$guesser->setDebug(true); // Logs to storage/logs/filename-guesser.log
testGuessFromHeaders.php).FilenameGuesser to add custom rules:
$guesser->addMimeMapping('application/octet-stream', 'bin');
guessFilename() via events (if using Laravel Events):
event(new FilenameGuessed($url, $filename));
NO_UPDATE_NEEDED (for prior assessment—this is the **full new assessment** for v1.0.2).
How can I help you explore Laravel packages today?