Comment Uploads 2.x

Legacy documentation for Comment Uploads 2.x.

The Comments Upload extension integrates with the native EE Comments Entries tag. It allows you to add an additional set of variables that enables the display of uploaded file attachments.

{exp:comment:entries} content {/exp:comment:entries} 

Variables

The following variables become available with the Comment Uploads extension enabled:

uploaded_file_count

{uploaded_file_count} 

This variable outputs the position number of the upload within the uploaded files. For use only with the uploaded_files variable pair.

uploaded_file_height

{uploaded_file_height} 

This variable outputs the height of the uploaded file, if it is an image file (ex: 100). For use only with the uploaded_files variable pair.

uploaded_file_id

{uploaded_file_id} 

This variable outputsthe unique ID of the file that has been uploaded (ex: 36). For use only with the uploaded_files variable pair.

uploaded_file_img_type

{uploaded_file_img_type} 

This variable outputs the numerical type of image the file is, if it is an image file (.JPG is 1, .GIF is 2, and .PNG is 3). For use only with the uploaded_files variable pair.

uploaded_file_name

{uploaded_file_name} 

This variable outputs the new name (and extension) of the file that has been uploaded (ex: 125-356-20091113111610-1.pdf). For use only with the uploaded_files variable pair.

uploaded_file_original_name

{uploaded_file_original_name} 

This variable outputs the original name (and extension) of the file that has been uploaded (ex: filename.pdf). For use only with the uploaded_files variable pair.

uploaded_file_size

{uploaded_file_size} 

This variable outputs the size in bytes of the file that has been uploaded (ex: 96809). For use only with the uploaded_files variable pair.

uploaded_file_size_kb

{uploaded_file_size_kb} 

This variable outputs the size in kilobytes of the file that has been uploaded (ex: 94.54). For use only with the uploaded_files variable pair.

uploaded_file_size_mb

{uploaded_file_size_mb} 

This variable outputs the size in megabytes of the file that has been uploaded (ex: 0.09). For use only with the uploaded_files variable pair.

uploaded_file_type

{uploaded_file_type} 

This variable outputs the type of the file that has been uploaded (ex: image/pjpeg or application/pdf). For use only with the uploaded_files variable pair.

uploaded_file_url

{uploaded_file_url} 

This variable outputs the complete URL path of the file that has been uploaded (ex: http://www.yoursite.com/images/uploads/comments/filename.jpg). For use only with the uploaded_files variable pair.

uploaded_file_width

{uploaded_file_width} 

This variable outputs the width of the uploaded file, if it is an image file (ex: 150). For use only with the uploaded_files variable pair.

uploaded_files_total

{uploaded_files_total} 

This variable outputs the total number of uploaded files for a particular comment.

Variable Pairs

The following variable pair becomes available with the Comment Uploads extension enabled:

uploaded_files

{uploaded_files} stuff {/uploaded_files} 

This variable pair allows you to display uploaded files and control the formatting for them within the Comment:Entries loop.

NOTE: This variable pair is required, should you wish to display any file-specific variables.

Conditionals

The following conditionals become available with the Comment Uploads extension enabled:

if uploaded_file_is_image

{if uploaded_file_is_image} image content {if:else} non-image content {/if} 

This conditional allows you to determine if the file uploaded is an image or not. If the file is an image, you can then use standard image formatting to display the file as an image.

if uploaded_file_user_can_delete

{if uploaded_file_user_can_delete} stuff {/if} 

This conditional evaluates to TRUE if the currently logged in user has the necessary permissions to delete the file(s).

if uploaded_files

{if uploaded_files} stuff {/if} 

This conditional simply allows you to check if any files were attached to a given comment.

Examples

You would normally just add the above variable pairs and variables to your existing Comment Entries code and it should work right away:

{exp:comment:entries
    sort="asc"
    limit="20"
}
    <div class="comment">
        <p>Posted by {name} on {comment_date format="%Y %m %d"}</p>
        <p>{comment}</p>

<!-- START Comment Uploads code -->
{if uploaded_files}
    <p>{uploaded_files_total} file(s) are attached to this comment:</p>
    {uploaded_files}
    {if uploaded_file_is_image}
        <p><a href="{uploaded_file_url}"><img src="{uploaded_file_url}" height="{uploaded_file_height}" width="{uploaded_file_width}" alt="image" /></a></p>
    {if:else}
        <p><a href="{uploaded_file_url}">Click here to Download this file</a></p>
    {/if}
    {/uploaded_files}
{/if}
<!-- END Comment Uploads code -->

{/exp:comment:entries}