5-Minute Quickstart
This walkthrough covers the four most common tasks with $this->wire()->media using an editorial yacht charter site (“Aegean Voyages”) as the example.
-
Upload a public asset with tags and localized metadata
<?phpdeclare(strict_types=1);namespace ProcessWire;$media = $this->wire()->media;$asset = $media->upload('/tmp/gocek-sunset-hero.jpg', ['title' => 'Gocek 12 Islands Sunset','alt' => 'Sailing yacht anchored at sunset across Gocek islands','tags' => ['hero', 'gocek', 'sunset'],]); -
Resize, extract a color palette, and render a responsive
<picture><?phpdeclare(strict_types=1);namespace ProcessWire;$lang = $this->wire()->languages ? $this->wire()->user->language : null;// ProcessWire-familiar resize/crop cached in entries_tbl_media_crops$heroCrop = $asset->size(1600, 900, ['format' => 'webp','quality' => 85,'sharpening' => 'soft',]);// Extract a 6-color palette for UI accents$palette = $asset->palette(6);// Render full responsive <picture> with LCP fetchpriority="high" and WebP sourceecho $asset->render(1600, 900, ['isFirst' => true,'alt' => $asset->alt($lang),'class' => 'hero-img','webpAdd' => true,]); -
Store a confidential module file in a Private Vault
<?phpdeclare(strict_types=1);namespace ProcessWire;$invoice = $media->uploadPrivate('commerce', '/tmp/charter-invoice-42.pdf', ['title' => 'Charter Invoice #42','custom_meta' => ['user_id' => $this->wire()->user->id],]);// Mint a 5-minute single-use signed download URL$signedUrl = $invoice->signedUrl(300, ['singleUse' => true]); -
Query ProcessWire pages referencing Media assets
Add a
FieldtypeMediafield (for examplehero_media) to a template, attach assets from the library, and query with standard ProcessWire selectors:<?phpdeclare(strict_types=1);namespace ProcessWire;$heroPages = $this->wire()->pages->find('hero_media.kind=image, hero_media.tags*=hero, limit=25');