Skip to content

Kirby 3.9.8

$file->type()

Returns the file type

$file->type(): string|null

Return type

string|null

Parent class

Kirby\Cms\File

Example

if($file = $page->file('myimage.jpg')):
    echo $file->type();
    // image
endif;


if($file = $page->file('terms.pdf')):
    echo $file->type();
    // document
endif;

if($file = $page->file('numbers.xls')):
    echo $file->type();
    // document
endif;


if($file = $page->file('software-1.0.0.zip')):
    echo $file->type();
    // archive
endif;


if($file = $page->file('some-movie.mov')):
    echo $file->type();
    // video
endif;


if($file = $page->file('styles.css')):
    echo $file->type();
    // code
endif;

All file types

Type Extensions
image jpg, gif, png, svg, ico, tiff, bmp, psd, ai, webp (since v3.2.0)
document md, pdf, doc, docx, xls, xlsx, ppt, csv, rtf
archive zip, tar, gz, gzip, tgz
code js, css, html, xml, json
video mov, avi, ogg, ogv, webm, flv, swf, mp4, mv4
audio mp3, m4a, wav, aiff, midi