Videos in ProcessWire image fields, next to images and in any order. No new field type: each video is stored as a poster image, with the video file next to it. The poster is created from the video's first frame, and editors can choose another frame later.
The module adds only what videos need: a player in the edit panel and a way to choose the poster frame. Everything else is core's image field, working as it always does. Uninstalling breaks nothing: your website keeps showing the videos, and the admin is a plain image field again.
Quick start
- Install: copy the
MediaFilesfolder tosite/modules/, go to Modules → Refresh and install Media Files (ProcessWire 3.0.154 or newer). - Enable videos: add
mp4to an image field's Valid file extensions (Details tab). - Show them: in your template, a poster with a video has
filedata('video'):
<?php foreach($page->gallery as $img):
if($img->filedata('video')): ?>
<video controls playsinline poster="<?= $img->url ?>" src="<?= $img->pagefiles->url . rawurlencode($img->filedata('video')) ?>"></video>
<?php else: ?>
<img src="<?= $img->url ?>" alt="<?= $sanitizer->entities($img->description) ?>">
<?php endif;
endforeach; ?>That's it. Editors add videos like images, and pick another poster frame with Set current frame as poster.
[!NOTE] Why
$img->filedata('video')and not$img->video?filedata()is core ProcessWire. A$img->videoproperty would come from the module and disappear when it is uninstalled, so your templates would break.$img->pagefiles->urlis core too: the URL of the page's files folder, where the video is.
Everything below is reference. Read it when you need it:
- Template examples and filedata keys
- Troubleshooting
- Uninstall
- For developers (adding videos from code, hooks, server limits): API.md
Template examples
Posters are normal Pageimages: resize, crop and focus work as for any image. The video is served as uploaded.
Multiple images field
<?php foreach($page->gallery as $img):
$video = $img->filedata('video');
$alt = $sanitizer->entities($img->description);
if($video):
$url = $img->pagefiles->url . rawurlencode($video);
$type = str_replace('ogv', 'ogg', $img->filedata('videoExt')); ?>
<video controls playsinline preload="none"
poster="<?= $img->width(1600)->url ?>"
width="<?= $img->width ?>" height="<?= $img->height ?>"
aria-label="<?= $alt ?>">
<source src="<?= $url ?>" type="video/<?= $type ?>">
</video>
<?php else: ?>
<img src="<?= $img->width(1600)->url ?>" alt="<?= $alt ?>"
width="<?= $img->width ?>" height="<?= $img->height ?>" loading="lazy">
<?php endif;
endforeach; ?>Single image field
A field with Maximum files allowed = 1 returns one Pageimage (or null when empty):
<?php $img = $page->hero;
if($img):
$video = $img->filedata('video');
if($video):
$type = str_replace('ogv', 'ogg', $img->filedata('videoExt')); ?>
<video autoplay muted loop playsinline poster="<?= $img->url ?>">
<source src="<?= $img->pagefiles->url . rawurlencode($video) ?>" type="video/<?= $type ?>">
</video>
<?php else: ?>
<img src="<?= $img->url ?>" alt="<?= $sanitizer->entities($img->description) ?>">
<?php endif;
endif; ?>Filedata keys
All keys are set on the poster image. On normal images they are empty (null).
| Key | Example | Notes |
|---|---|---|
filedata('video') | "example.mp4" | Video filename. Use this to tell videos from images. Same as videoFilename. |
filedata('videoFilename') | "example.mp4" | Video filename with extension. |
filedata('videoBasename') | "example" | Video filename without extension. |
filedata('videoExt') | "mp4" | Lowercase extension: mp4, webm or ogv. For the type attribute, ogv is video/ogg. |
filedata('videoFilesize') | 1234567 | Size in bytes, when the video was uploaded or renamed. |
filedata('videoFilesizeStr') | "1.2 MB" | Same size, formatted for display (e.g. next to a download link). |
Video URL: $img->pagefiles->url . rawurlencode($img->filedata('video'))
Video path on disk: $img->pagefiles->path . $img->filedata('video')
Troubleshooting
"Invalid image" when uploading a video. Check that the module is installed and that the field's Valid file extensions include mp4, webm or ogv.
"The video is larger than the server allows (…)" The limit is PHP's post_max_size, or the field's Max file size if that is lower. To accept larger videos, raise the server limits (see API.md).
The video plays in the admin but not on the website. Videos are stored as uploaded, not converted. HEVC (H.265, the iPhone default) plays mainly in Safari: use mp4 with H.264. Also check that the type attribute matches the file (ogv is video/ogg).
"Video uploads are off …" or "Video uploads and editing are off …" A ProcessWire update changed something the module relies on. Images and the website keep working. Update the module, or report the message and your ProcessWire version.
Uninstall
Nothing on the website breaks: posters stay normal images, and video files stay on disk. Uninstalling lists the fields that still allow video extensions. Remove those extensions if editors should no longer upload videos (without the module, core rejects them as "Invalid image").
License
MIT
More modules by diogo
- ProcessAdminCustomPages by diogo
- Portugues by diogo
- TextformatterImageTags by diogo
Image Field Markup
Allows you to use image fields inside markup languages, notably, Markdown and Textile in Processwire text fields3TextformatterImageFieldMarkup by diogo- Added 4 hours ago by diogo
Install and use modules at your own risk. Always have a site and database backup before installing new modules.