Documentation

MediaUploadInterface

Implements media upload and delete functionality.

Table of Contents

Methods

checkUploadedFile()  : string
Checks that uploaded file meets the requirements. Returns new filename.
copyUploadedFile()  : void
Copy uploaded file to the media collection.
deleteFile()  : void
Delete real file from the media collection.
renameFile()  : void
Rename file inside the media collection.

Methods

checkUploadedFile()

Checks that uploaded file meets the requirements. Returns new filename.

public checkUploadedFile(UploadedFileInterface $uploadedFile[, string|null $filename = null ][, array<string|int, mixed>|null $settings = null ]) : string
Parameters
$uploadedFile : UploadedFileInterface
$filename : string|null = null
$settings : array<string|int, mixed>|null = null
Tags
example

$filename = null; // Override filename if needed (ignored if randomizing filenames). $settings = ['destination' => 'user://pages/media']; // Settings from the form field. $filename = $media->checkUploadedFile($uploadedFile, $filename, $settings); $media->copyUploadedFile($uploadedFile, $filename);

throws
RuntimeException
Return values
string

copyUploadedFile()

Copy uploaded file to the media collection.

public copyUploadedFile(UploadedFileInterface $uploadedFile, string $filename[, array<string|int, mixed>|null $settings = null ]) : void

WARNING: Always check uploaded file before copying it!

Parameters
$uploadedFile : UploadedFileInterface
$filename : string
$settings : array<string|int, mixed>|null = null
Tags
example

$filename = null; // Override filename if needed (ignored if randomizing filenames). $settings = ['destination' => 'user://pages/media']; // Settings from the form field. $filename = $media->checkUploadedFile($uploadedFile, $filename, $settings); $media->copyUploadedFile($uploadedFile, $filename);

throws
RuntimeException

deleteFile()

Delete real file from the media collection.

public deleteFile(string $filename[, array<string|int, mixed>|null $settings = null ]) : void
Parameters
$filename : string
$settings : array<string|int, mixed>|null = null

renameFile()

Rename file inside the media collection.

public renameFile(string $from, string $to[, array<string|int, mixed>|null $settings = null ]) : void
Parameters
$from : string
$to : string
$settings : array<string|int, mixed>|null = null

        
On this page

Search results