Handling image uploads

2 posts by 2 authors in: Forums > CMS Builder
Last Post: November 14, 2008   (RSS)

Re: [macwebster] Handling image uploads

By Dave - November 14, 2008

Hi Julia,

The Code Generator should generate image tags for both. Usually it looks something like this:

I've highlighted the important parts in red.

<!-- STEP 2a: Display Uploads for field 'uploads' (Paste this anywhere inside STEP2 to display uploads) -->
<?php foreach ($newsRecord['uploads'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

<?php endif ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->


What this code does is display the thumbnail if it's available, or if not then the full size image, or if that's not available then a link to the file (since it's probably a PDF or something). So we take the thumbnail image tag and link it to the full size image url like this:

<a href="<?php echo $upload['urlPath'] ?>">
<img src="<?php echo $upload['thumbUrlPath'] ?>"
width="<?php echo $upload['thumbWidth'] ?>"
height="<?php echo $upload['thumbHeight'] ?>"
alt="" /></a>


Hope that helps!
Dave Edis - Senior Developer
interactivetools.com