# MediaFiles: API and internals For developers and agents working with the module. Install, setup and frontend examples are in [README.md](README.md). ## Data model A video is two files in the page's files directory (`$page->filesManager->path`): | File | Example | Role | |---|---|---| | Poster | `example_video-poster.jpg` | A normal `Pageimage` in the image field. Holds the description, custom fields, sort order and the link. | | Video | `example.mp4` | A plain file next to it. Not part of the field value. | The link is stored **only on the poster**, in `filedata()`. Filenames never pair poster and video, except for 0.9.x content (see [Upgrading](#upgrading-from-09x)). | Key | Type | Example | |---|---|---| | `video` | string | `"example.mp4"` | | `videoFilename` | string | `"example.mp4"` | | `videoBasename` | string | `"example"` | | `videoExt` | string | `"mp4"` (`mp4`, `webm` or `ogv`) | | `videoFilesize` | int | `1234567` | | `videoFilesizeStr` | string | `"1.2 MB"` | All keys are written together on upload and rename. `video` and `videoFilename` are always equal. Size keys reflect the file at that moment. Posters from the admin are jpg, posters added with `addVideo()` can also be png. Their name ends in `_video-poster` plus, after a rename or frame change, `-`. ### Telling videos from images ```php $video = (string) $img->filedata('video'); // '' for normal images ``` This works with or without the module. Inside the admin or a module, `$modules->get('MediaFiles')->getVideo($img)` returns the same, but also checks that the file exists and resolves unsaved 0.9.x posters by name. ### Adding a video from code ```php $page->of(false); $poster = $modules->get('MediaFiles')->addVideo($page->gallery, '/path/to/example.mp4', '/path/to/example-frame.jpg'); $poster->description = 'A short description'; // or custom fields: $poster->setFieldValue('image_alt', '…') $page->save('gallery'); ``` `addVideo(Pageimages $images, string $videoFile, string $posterFile): Pageimage` copies the video next to the field's files, adds the poster, writes all filedata keys and returns the poster. Save the page afterwards. - The video name is sanitized like an uploaded file (`My Video.mp4` → `my_video.mp4`) and gets `-1`, `-2`… if taken. The poster is named `