API / Minn\Media / Uploads

Uploads final readonly class

Minn\Media\Uploads · public/minn/src/Minn/Media/Uploads.php · 135 lines

The uploads directory: paths, URLs, the allowed types, and landing a file.

Constants and properties

constMIMES = array ( 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'webp' => 'image/webp', 'pdf' => 'application/pdf', 'txt' => 'text/plain', 'mp4' => 'video/mp4', 'mp3' => 'audio/mpeg', 'zip' => 'application/zip', )

extension => canonical mime

privatereadonly Minn\Front\Permalinks $permalinks

Promoted from the constructor.

privatereadonly string $baseDir

Promoted from the constructor.

Public

new__construct(Minn\Front\Permalinks $permalinks, string $baseDir)#
methodbaseDir(): string#

The uploads directory on disk.

methodbaseUrl(): string#

The uploads directory's URL.

methodurlFor(string $relativePath): string#

The URL of a file by its relative path.

methodpathFor(string $relativePath): string#

The path of a file by its relative path.

staticsanitizeName(string $filename): string#

A safe file name: one extension. Every dot-separated part between the base and the last extension that is not itself an allowed extension is joined with an underscore, so "shell.php.png" lands as "shell_php.png" and no handler can be talked into running it.

methodrelativeOf(string $absolutePath): ?string#

A stored file's path relative to the uploads folder, or null for a file outside it.

staticattachmentFiles(string $file, array $meta, ?array $backupSizes): array#

Every file an attachment owns, in deletion order: the legacy thumb, each sub-size, the original image, the backup sizes, then the file itself.

$metaarray<string, mixed>the attachment metadata
$backupSizesarray<string, array<string, mixed>>|null
@return list<string> absolute paths, unique, only the main file checked for existence
staticlayout(string $uploadPath, string $uploadUrlPath, string $siteUrl, string $contentDir, string $contentUrl, string $abspath, bool $yearMonth, string $time): array#

Where uploads live, from the site's options: the default folder under wp-content, a relative upload_path under ABSPATH, or an absolute one; the URL likewise, with year/month subfolders when the site asks.

@return array{path: string, url: string, subdir: string, basedir: string, baseurl: string, error: false}