Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Curl File Downloader Laravel Package

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.

View on GitHub
Deep Wiki
Context7
## 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.


Implementation Patterns

Core Workflow

  1. Input: Pass raw URLs (with or without extensions) to guessFilename().
  2. Context: Inject HTTP headers (e.g., Content-Type) for extension inference:
    $guesser->setHeaders(['Content-Type' => 'video/mp4']);
    $filename = $guesser->guessFilename($url);
    
  3. Output: Use the guessed filename for storage, API responses, or metadata.

Integration Tips

  • Laravel Storage: Chain with Storage::put():
    $path = $guesser->guessFilename($url);
    Storage::disk('s3')->put($path, file_get_contents($url));
    
  • Queue Jobs: Process URLs asynchronously (e.g., for video downloads):
    DownloadVideoJob::dispatch($url)->onQueue('videos');
    
  • Service Providers: Bind the guesser to the container for dependency injection:
    $this->app->singleton(FilenameGuesser::class, fn() => new FilenameGuesser());
    

Gotchas and Tips

Pitfalls

  • Header Dependency: Extension guessing relies on 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.
  • Fallback Logic: The package defaults to .mp4 for unrecognized types. Override with a custom strategy:
    $guesser->setDefaultExtension('webm');
    
  • Edge Cases: URLs with query strings (e.g., ?id=123) may break parsing. Use parse_url() to sanitize inputs:
    $baseUrl = parse_url($url, PHP_URL_PATH);
    

Debugging

  • Verbose Mode: Enable logging for header/guessing details:
    $guesser->setDebug(true); // Logs to storage/logs/filename-guesser.log
    
  • Test Suite: Use the included tests as a reference for edge cases (e.g., testGuessFromHeaders.php).

Extension Points

  • Custom MIME Mappings: Extend FilenameGuesser to add custom rules:
    $guesser->addMimeMapping('application/octet-stream', 'bin');
    
  • Preprocessing: Hook into 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).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
cadot.eu/make
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky