Different urls based on file type

5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 4, 2012   (RSS)

By KCMedia - June 30, 2012

Hi

I have some files that are uploaded to the site and they require different urls based on the file type

Eg PDF, xls, docs will all have one kind of URL opened using google docs viewer and then video files and images will be opened using Shadowbox to display them.

Any help will be great
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] Different urls based on file type

By gkornbluth - July 1, 2012

Hi Craig,

Here's a recipe from my CMSB Cookbook thecmsbcookbook.com might get you started.

USING IF STATEMENTS TO DEFINE OUTPUT BASED ON A FILE EXTENSION

If you need to publish specific code that’s based on the type of file that you’ve uploaded into an upload field, like a .swf flash file, here’s the trick. Just use:
<?php if ($upload['extension'] == 'swf'): ?>
or for the second through next to last if parameter in the list (the last one gets an <?php else: ?> instead of a <?php elseif...)
<?php elseif ($upload['extension'] == 'swf'): ?>
You can use this for non upload fields as well:
<?php if ($your_fieldRecord['extension'] == 'doc'): ?>
or
<?php elseif ($your_fieldRecord['extension'] == 'doc'): ?>
And , don’t forget that every if statement must be closed with an <?php endif ?>

Hope that helps,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Different urls based on file type

By KCMedia - July 1, 2012

Hi Jerry

it isnt Craig he is away it is Mark.

thanks for that i am not 100% but this what we have working now for all kinds of pdf, word, excel doc types that get opened.

<?php foreach ($downloadRecords as $record): ?>
<?php foreach ($record['upload'] as $index => $upload): ?>
<a href="http://docs.google.com/gview?url=http://www.domain.com<?php echo $upload['urlPath'] ?>&embedded=true" target="_blank">Download <?php echo htmlencode($upload['info1']) ?></a><br/><br/>
<?php endforeach ?>
<?php endforeach ?>
<?php if (!$downloadRecords): ?>
<?php endif ?>

what we need to do is also upload video files that will open in shadowbox using just the rel="shadowbox" in the url but only if it is a video and not anything else.
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] Different urls based on file type

By gkornbluth - July 1, 2012

Hi Mark,

I'll try to find something more specific, but basically I'd use the approach above in the foreach loop to sniff out the extension and if it's a video extension, then execute the shadowbox video code.

You might also look at jwplayer if you can't get shadowbox to work

Hope that helps,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php