Feature most recent file upload

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 18, 2008   (RSS)

By zip222 - July 17, 2008

My client needs to upload a new file to a page each month. The most recent file needs to be highligted in some way, and the older files need to remain visible but in a clearly separate section of the page. I know this can be done by setting up two different file uploads, but I was wondering if there is a way for it to be done with just a single upload (to make things simpler for the client). here is the current version, using a single upload, which just generates a single list of files.

<?php
require_once "/usr/www/users/fluency/cmsAdmin/lib/viewer_functions.php";

list($customRecords, $customDetails) = getRecords(array(
'tableName' => 'custom',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$customRecord = $customRecords[0]; // get first record

?>
<?php echo "<?xml version='1.0'?>\n"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
body { font-family: arial; }
.instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
</style>
</head>
<body>
<h1>File Viewer</h1>
<ul>
<?php foreach ($customRecord['archived_files'] as $upload): ?>
<li><a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['info1'] ?></a></li>
<?php endforeach ?>
</ul>

</body>
</html>

Re: [jdancisin] Feature most recent file upload

By Dave - July 18, 2008

jdancisin,

Thanks for your patience!

Can we assume that the "newest" upload will always be sorted to the top? If so you could just use two viewers and a counter to keep track of the upload we're displaying. Here's the code:

<h1>File Viewer 1</h1>
<ul>
<?php $uploadCount = 0; ?>
<?php foreach ($customRecord['archived_files'] as $upload): ?>
<?php if (++$uploadCount > 1) { continue; } ?>
<li><a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['info1'] ?>...</a></li>
<?php endforeach ?>
</ul>

<h1>File Viewer 2</h1>
<ul>
<?php $uploadCount = 0; ?>
<?php foreach ($customRecord['archived_files'] as $upload): ?>
<?php if (++$uploadCount < 2) { continue; } ?>
<li><a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['info1'] ?>...</a></li>
<?php endforeach ?>
</ul>


A little explanation for the code. The ++$variable means "add one to this" and "continue" means skip the rest and continue with the next item in the foreach.

And if you want them in reverse order (with the bottom upload showing first, just replace _both_ foreach lines with this:

<?php foreach (array_reverse($customRecord['archived_files']) as $upload): ?>

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