MAKE AN IMAGE AN ACTIVE DOWNLOAD LINK - Aug 3rd, 2010


This example uses a multi record editor called test3 that contains 2 upload fields, “pdf” and “image”

The code on the PHP viewer page to display the image as an active link is below.

The basic structure of the code you want to appear in the client’s browser is.



<a href="path to your pdf upload"><img src="path to the thumbnail" width="thumbnail width" height=”thumbnail height"
alt="alternate description of link" /> any other text that you want under the image</a>



It’s also a good idea to put a link on your page that lets the visitor know that they’ll need at least the free
Adobe PDF reader to open the PDF document. The link to the free reader is: http://get.adobe.com/reader/

In the PHP code to accomplish this there is one main foreach loop that says look at each record in the test3 table. This
loop is closed with an endforeach at the end of the code block.

Then there’s a nested foreach loop for the pdf uploads that says look for the pdf upload path in each of the test3
records and display the path. This loop is closed at the end of the pdf code.

There’s a 3rd nested foreach loop to look for image uploads and display them as images. This loop is closed at the end
of the image display code.

These loops are extracted from the full code in the CMS Admin code generator. As long as you know what type of uploads
you’re working with, you don’t have to use all of the “if” tests in the code. This makes your page much cleaner
and easier to understand.



<?php foreach ($test3Records as $record): ?>
<?php foreach ($record['pdf'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>"> <?php endforeach ?>

<?php foreach ($record['image'] as $upload): ?>

<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo
$upload['thumbHeight'] ?>" alt="" />Click On the Image for the PDF</a>
<?php endforeach ?><?php endforeach ?>




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service