How to make single link change automatically based on filetype

7 posts by 3 authors in: Forums > CMS Builder
Last Post: January 14, 2009   (RSS)

Re: [eriqcook] How to make single link change automatically based on filetype

By ross - January 12, 2009

Hi there.

Thanks for posting!

I think what I'll do is just go over the code briefly so we can both be sure I am on the right track here :).

You are definitely off to a good start with the if/else approach, so that's going to work.

First off, the way I see it, each article will have the option of linking to a full article page or right to a file download.

The idea behind those if/elses is going to be something like this:

if upload fields is not blank (which means you've uploaded a file), display a link to download the file.

if the upload field is blank (you have not uploaded a file), display a link to the full article.

Does that sound about right? Let me know and I'll go over the code in more detail.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] How to make single link change automatically based on filetype

Thank you for the quick reply. Yes that's exactly what I want to do. Not sure how to code exactly

Re: [eriqcook] How to make single link change automatically based on filetype

By Dave - January 13, 2009

Hi Eriq,

Try something like this:

<?php if ($upload['extension'] == 'gif'): ?>
<a href="...">View Image</a>
<?php elseif ($upload['extension'] == 'pdf'): ?>
<a href="...">View PDF</a>
<?php else: ?>
<a href="...">View All other files</a>
<?php endif ?>


Let me know if that works for you or if you run into any problems.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] How to make single link change automatically based on filetype


Hi Eriq,

Try something like this:

<?php if ($upload['extension'] == 'gif'): ?>
<a href="...">View Image</a>
<?php elseif ($upload['extension'] == 'pdf'): ?>
<a href="...">View PDF</a>
<?php else: ?>
<a href="...">View All other files</a>
<?php endif ?>


Let me know if that works for you or if you run into any problems.

Re: [eriqcook] How to make single link change automatically based on filetype

Strange. I typed in a long reply (using the "Quote" button) and it posted your quote with my response missing! [crazy]

Anyway, what I said was that I changed the code to match to the correct file type, but if you look at the following page:

http://www.mtrip.org/v2/cmstest.php

You'll see it only shows "View Page" (for "non file upload" articles). It's supposed to say "View PDF" if the filetype is a PDF, or "View Page" if there's no file uploaded and just a standard article page.

If you click on the "View Page" link however, it loads the article detail page and displays the file at the very bottom (IF the file exist). Not exactly how I wanted it to work though.

It may have something to do with how I have everything setup on the back side. I don't know. You may need to look at how I have things setup internally to see what's wrong here.

Thank you for your help...

Re: [eriqcook] How to make single link change automatically based on filetype

By Dave - January 14, 2009

Hi Eriq,

Can you attach the cmstest.php file to this post or email me CMS and FTP login details to dave@interactivetools.com (email, don't post login details to the forum) so I can take a closer look at the code?

Thanks!
Dave Edis - Senior Developer
interactivetools.com