Skip to content

Displaying Uploads

For most fields, displaying a value only takes a single tag. Uploads are different: each upload carries multiple pieces of information (URL, width, height, thumbnails, captions), and a field can hold multiple uploads, so viewers loop over them.

The generator produces a block like this for each upload field (a field named images in this example):

<!-- STEP 2a: Display Uploads for field 'images' (Paste this anywhere inside STEP2 to display uploads) -->
<?php foreach ($record['images'] as $index => $upload): ?>
... each upload is displayed here ...
<?php endforeach ?>

Inside the loop, display upload attributes the same way as record fields:

<?php echo $upload['urlPath'] ?>

Uploads are returned in the order they appear in the record editor, where they can be re-arranged by drag-sorting.

Example: thumbnails linked to full-size images

Section titled “Example: thumbnails linked to full-size images”

For a clickable gallery, wrap each thumbnail in a link to the full-size image’s urlPath:

<?php foreach ($record['images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $upload['urlPath'] ?>">
<img src="<?php echo $upload['thumbUrlPath'] ?>"
width="<?php echo $upload['thumbWidth'] ?>"
height="<?php echo $upload['thumbHeight'] ?>"
alt="<?php echo $upload['info1'] ?>">
</a>
<?php endif ?>
<?php endforeach ?>
AttributeDescription
filePathServer path to the uploaded file, e.g. /var/www/example.com/cmsb/uploads/photo.jpg
urlPathWebsite location of the file, e.g. /cmsb/uploads/photo.jpg
filenameThe file name, e.g. photo.jpg
extensionFile extension, e.g. jpg
isImage1 if the file is an image (gif, jpg, jpeg, png, or webp)
filesizeFile size in bytes
AttributeDescription
info1, info2, …Extra per-upload fields defined in the field editor. By default info1 is “Title” and info2 is “Caption” — useful for alt text, file descriptions, or gallery captions.

To change the info field labels, go to CMS Setup > Database Editor, click modify beside the upload field, and find the Upload Fields settings.

AttributeDescription
hasThumbnail1 if the upload is an image with a generated thumbnail
width, heightDimensions of the uploaded image
thumbUrlPathWebsite location of the generated thumbnail (thumbUrlPath2thumbUrlPath4 for additional thumbnail sizes)
thumbFilePathServer path to the thumbnail (thumbFilePath2thumbFilePath4 for additional sizes)
thumbWidth, thumbHeightThumbnail dimensions (thumbWidth2/thumbHeight2 etc. for additional sizes)

These attributes are used internally by the program and are listed for completeness:

AttributeDescription
orderPosition of the upload within the field, set by drag-sorting uploads in the editor
mediaNumRecord number of the linked Media Library file, when the upload references one
storageIdentifier of the storage backend holding the file
num, createdTime, tableName, fieldName, recordNum, preSaveTempIdInternal bookkeeping values
Documents CMS Builder 3.83