We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Choose original upload if file type is a GIF

How Do I?

adamprocter's avatar
adamprocter
228 posts
10 years ago
adamprocter's avatar adamprocter

So I have a website in which I upload images which get formated using the file manager ssystem but some of these are animated gifs and so I need to access the original uploaded file as the file manager compressed one is not longer animated I was hoping I could do an

If file type = gif

i.e

{if file type = gif}

{image}
{ifelse}
{image:midsize}
{/if}
       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
10 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

Try:

{if filename *= ".gif"}it's a gif{/if}
       
Natetronn's avatar
Natetronn
161 posts
10 years ago
Natetronn's avatar Natetronn

Maybe try the Variable Pair Usage along with the {extension} and the {url} variables.

For example: (untested)

{image}
    {if extension == 'gif'}
        {url}
    {if:else}
        {url:midsize}
    {/if}
{/image}

Edit to add:

You can use the Comparison Operator as Pedro suggested and the file name though, it’s file_name, not filename. Either one should work though, I would think the Contains Comparison Operator uses a tiny bit more resources. I’m not sure, however.

       
adamprocter's avatar
adamprocter
228 posts
10 years ago
adamprocter's avatar adamprocter

Thanks look simple to try

{exp:channel:entries channel="delightful" limit="10"}
<div class="entry">
{if file_name *= ".gif"}
{image}
{if:else}
{image:midsize}
{/if}
Submitted by {submitted_by}
{reasoning}

{rating}
</div>
        {/exp:channel:entries}
</div>

But I get this ?

Parse error: syntax error, unexpected ‘FALSE’ (T_STRING) in expressionengine/libraries/Functions.php(689) : eval()’d code on line 12

       
adamprocter's avatar
adamprocter
228 posts
10 years ago
adamprocter's avatar adamprocter

Nate your method worked

{image}
    {if extension == 'gif'}
        {url}
    {if:else}
        {url:midsize}
    {/if}
{/image}
       
adamprocter's avatar
adamprocter
228 posts
10 years ago
adamprocter's avatar adamprocter

thanks much better

http://delightfulelements.co.uk/

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
10 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

I like his method better. The only thing wrong with the other one is that it had to be enclosed in the tag as well.

       
Natetronn's avatar
Natetronn
161 posts
10 years ago
Natetronn's avatar Natetronn
I like his method better. The only thing wrong with the other one is that it had to be enclosed in the tag as well.

Right!

So, just to thorough for future reference, that would look something like this:

{exp:channel:entries channel="delightful" disable="categories|category_fields|member_data|pagination" limit="10"}
    <div class="entry">
        {image}
            {if file_name *= '.gif'}
                {url}
            {if:else}
                {url:midsize}
            {/if}
        {/image}
        Submitted by {submitted_by}
        {reasoning}

        {rating}
    </div>
{/exp:channel:entries}

Note: if you’re not using everything in the Channel Entries Tag consider turning some of it abilities off via the disable param. This can help performance.

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
10 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

Yep. The extension method seems nicer and cleaner, but I can see the use for the other logic in other scenarios. Either way it just proves how flexible EE is. 😊

       
Natetronn's avatar
Natetronn
161 posts
10 years ago
Natetronn's avatar Natetronn

Yes, I love that they added the extra operators.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.