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: [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

Re: [kcmedia] Different urls based on file type

By gkornbluth - July 4, 2012

Hi Mark,

Sorry that it took so long.

Here's the detail page code I'm using with the jwplayer and a multi-record section called articles.

Hope it helps.

Jerry Kornbluth

Head code:
<script type="text/javascript" src="Scripts/jwplayer.js"></script>
Body Code
<?php if ($articlesRecord['article_images_or_video']): ?>
<table width="100%" border="0" align="center" cellpadding="5">
<tr >
<?php foreach ($articlesRecord['article_images_or_video'] as $upload): ?><?php if ($upload['extension'] == 'mp4'): ?>
<td align="center" valign="top" >
<span class="body-text-bold-9"><br />
<?php echo $upload['info1']; ?></span><br />
<span class="body-text-9"><?php echo $upload['info2']; ?><br /><br /></span>
<div id="container">&nbsp;</div>
<script type="text/javascript">
jwplayer("container").setup({

file: "http://96.0.19.45<?php echo $upload['urlPath'] ?>",
height: 420,
width: 510,
image: "http://96.0.19.45<?php foreach ($articlesRecord['video_image'] as $upload): ?><?php echo $upload['thumbUrlPath'] ?><?php endforeach ?>",
autostart: false,
modes: [
{ type: "html5" },
{ type: "flash", src: "player.swf" }
]

});
</script><br /><br /><hr align="center" color="#8FB2D4" width="300">
</td>
<?php else: ?><td valign="top" align="center"><br /><span class="body-text-bold-9">
<?php echo $upload['info1']; ?></span><br />
<span class="body-text-9">
<?php echo $upload['info2']; ?><br /><br /></span><img border="5" style="border-color:#89aed2" src="<?php echo $upload['thumbUrlPath2'] ?>" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" alt="" /><br /><br /><hr align="center" color="#8FB2D4" width="300">

<?php endif ?></td><?PHP $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?PHP endif; ?><?php endforeach ?><?php endif ?></tr></table></td>
</tr></table><br />
</td>
</tr>
</table>

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