<if type-from-data></if>
Provided by module: Tags: RXML tags
Compares if the variable's data is known content type and tries to match
that content type with the content type pattern.
This test is currently only capable of recognizing several common image
formats. If the content format isn't recognized then the fallback content
type in the Content Types module is tested against the pattern. That type
is "application/octet-stream" by default. That also means that if the
variable content is unknown and there is nothing to test the content type
from, it will always return true:
<set variable='var.fake-image' value='fakedata here'/>
<if type-from-data='var.fake-image'>It is an image</if> |
It is an image |
While the correct way would be:
<set variable='var.fake-image' value='fakedata here'/>
<if type-from-data='var.fake-image is application/octet-stream'>
Not known content type!
</if> |
Not known content type!
|
This is an Eval plugin.
Related tags: <if#type-from-filename>, <cimg>, <guess-content-type>,
<emit#dir>.
<nocache>
<form method='post' enctype='multipart/form-data'>
<input type='file' name='image' />
<input type='submit' name='upload' />
</form>
<if variable='form.image' and='' sizeof='form.image < 2048000'>
File is less than 2MB
<if type-from-data='form.image is image/*'>
It's an image!
</if>
<elseif type-from-filename='form.image is text/*'>
It is a text file of some sort.
</elseif>
<elseif type-from-filename='form.image is application/msword,application/pdf'>
The image is a MS word- or pdf file.
</elseif>
<elseif type-from-filename='form.image is application/octet-stream'>
Invalid content type, type is unknown!
</elseif>
</if>
<else>File larger than 2MB</else>
</nocache> |