Latest Register Log In

+ Advanced Search

Custom File Attachment Fields

Custom File Attachment Fields
By
Mar 21, 2004 (Edited Mar 10, 2014)

By using custom file fields, you can have you visitors upload several files at once for a single listing/category/etc. For listings and comments this isn't so important since you can already let people upload any number of files, but sometimes you may want a particular image separated from the others (for example, you can use a custom file field for a company logo while the regular upload area is used for product images). You can also add file uploads to categories and members using custom file fields.

In order to get started on creating a custom file field, visit Admin Panel -> Customizations -> Add Fields. Select the type of object (listing, category, etc), then for "input type" select "file attachment". Note it will automatically append 'attach' to the name you give the field. Once you click 'Add Field' the template code will be added to the custom field add/edit template as usual.

Now that you have the custom file field working, you'll want to make use of it in the display (most likely in the 'show listings in category' and/or 'main index' templates for a category, the listing bit or listing details for listings, or the profile for a member). Here's a reference of the template variables you will have available for such display... replace 'CUSTOMATTACH' in each example with the uppercase version of the name of your custom file attachment field. These examples assume it's a category field, replace {CAT with the appropriate prefix if it's another type of field.

{CATCUSTOMATTACHTITLE} - The name of the file for display purposes (the same name it had on the computer of the person who uploaded it).
{CATCUSTOMATTACHNAME} - The actual name on disk of the file in the attachments directory.
{CATCUSTOMATTACHDOWNLOADS} - The number of times the file has been downloaded so far.
{CATCUSTOMATTACHFILESIZE} - The size, in bytes, of the file.
{CATCUSTOMATTACHKB} - The size, in kilobytes, of the file.
{CATCUSTOMATTACHWIDTH} - For images, the width of the image in pixels.
{CATCUSTOMATTACHHEIGHT} - For images, the height of the image in pixels.
{CATCUSTOMATTACHDOWNLOADURL} - A download url which you can put in an a href HTML tag for a link or an img tag to display an image.
{CATCUSTOMATTACHTHUMBURL} - A thumbnail url which you can put in an HTML tag to display.
-- Optional parameters: width and height. Example: {CATCUSTOMATTACHTHUMBURL[500 <,> 300]} for a 500x300 thumbnail.
{CATCUSTOMATTACHTHUMBIMAGE} - The full img tag for a thumbnail.
{CATCUSTOMATTACHISIMAGE} - Determines if the file is an image. (new in 8.0)
{CATCUSTOMATTACHIMAGE} - The full image code of the thumbnail of the image. (new in 8.0)
{CATCUSTOMATTACHSLIDELINK} - A thumbnail that opens in a lightbox when clicked (images only).

To conditionalize the display to only show when there's a file attached, use ... around it. Some common examples of what you'll want to use as your display template code:

Download Link: <a href="{CATCUSTOMATTACHDOWNLOADURL}">Download {CATCUSTOMATTACHTITLE}</a>
Thumbnail of an image (use large thumbnails to display full image, this is much more kind to the server than using the download url because it caches): <img src="{CATCUSTOMATTACHTHUMBURL[100 <,> 100]}">


Note: In all the examples above, replace CUSTOMATTACH and customattach with the name of the custom file attachment field you've added. If you're doing this for a listing field instead of a category field, replace {CAT with {LINK everywhere above... for a member field replace {CAT with {MEMBER.





Description Creating, configuring and using custom attachments.
Rating
Views 2,637 views. Averaging 0 views per day.
Similar Listings