Load an icon up only if a file has been loaded up

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 11, 2014   (RSS)

This is quite hard to explain, I want to be show an icon for a pdf, a word document or a link to webpage. I want it to only show if a file has been added to the CMS entry. So if there is nothing loaded up then the icon disappears. I ahev done something similar before but cannot work out how I have done it.

By Damon - April 9, 2014

Hi,

You can use the file extension code to determine what the file type is:

<?php echo $upload['extension'] ?>

Then either you an if statement (if pdf display pdf icon) or you could control the icons using CSS:

... class="<?php echo $upload['extension'] ?>

Let me know what method you want to go with and I can provide more details.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

I tried the fle extension option but I obviously wasn't doing it properly, could you give me instructions for both methods for me to try again please.

Thanks for your help.

i have got this working for both pdfs and word documents:

<?php foreach ($mindfulnessRecord['word_uploads'] as $index => $upload): ?>
         <p class="intro"><?php if($upload['extension']=="docx"):?>
               <img src="../images/word-icon.png" width="25" height="28">
<?php endif ?>
          <a href="<?php echo $upload['urlPath'] ?>" target="_blank"><?php echo $upload['info1'] ?></a></p>
<?php endforeach ?>

But I also need it to work for when I load content/links into a wysiwyg editor, can you explain how I can do it that please.