CartThrob 9 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

Get Download Link

A video tutorial on this tag is available..

get_download_link builds an encrypted download URL that points to CartThrob download_file_action.

Use this tag when you want a clickable/shareable download link (for example in account, invoice, or order-email templates). If you do not want a visible link, use download_file_form instead.

This tag is a single output tag (not a form tag).

See also:

Parameters

Field/entry lookup:

Using a file location:

field

Custom field short name that contains a download path.

Use with entry_id. When both are provided, CartThrob reads that entry field value and resolves file-server paths.

field="product_download_url"

entry_id

Entry ID used with field to locate the download path.

entry_id="123"

file

Protected file path/URL source.

Use an absolute server path (/var/www/...) or a full URL. Relative web-root paths are not reliable for this flow.

file="/var/www/html/themes/user/cartthrob/images/cartthrob_logo_bg.jpg"

free_file

File path/URL source that generates a free-download token (FI path), not member/role restricted by default.

free_file="/themes/user/cartthrob/images/cartthrob_logo_bg.jpg"

member_id

Restrict the generated link to a specific member ID.

Supported dynamic values include CURRENT_USER, {logged_in_member_id}, and {member_id}.

member_id="CURRENT_USER"

group_id

Add a group/role restriction token to the generated link.

Supported dynamic values include {logged_in_group_id} and {group_id}.

group_id="6"

language

Adds an L query parameter to the generated download URL.

language="en"

debug

Outputs file-debug information for the resolved file source.

Useful when validating file paths and server-path resolution.

debug="yes"

Form Fields

This tag does not output a form.

(Anchor kept for compatibility with older links.)

Behavior and Constraints

  1. Output URL targets download_file_action and includes encrypted query parts (for example FI/FP, plus optional member/group/language tokens).
  2. If field + entry_id are provided and resolve to a path, that path is used as the file source.
  3. If member_id or group_id is set, free_file mode is cleared so a protected-file token is generated.
  4. If no usable file source is provided, the generated link will still point to the action but download processing will fail with a missing/unauthorized file error.
  5. debug="yes" is intended for troubleshooting and should not be enabled in production output.

Security note: this tag is designed to obfuscate/encrypt file references and route downloads through CartThrob action checks. It does not provide built-in time expiry, IP limits, or download-count throttling.

For more advanced download lifecycle controls (tracking, stricter governance, extended link policies), use additional tooling on top of this flow.

Examples

Use an entry file field (common purchased-download pattern):

{exp:cartthrob:order_items member_id="CURRENT_USER"}
    <a href="{exp:cartthrob:get_download_link field='product_download_url' entry_id='{item:entry_id}' member_id='CURRENT_USER'}">Download</a>
{/exp:cartthrob:order_items}

Free file link:

<a href="{exp:cartthrob:get_download_link free_file='/themes/user/cartthrob/images/cartthrob_logo_bg.jpg'}">Download free file</a>

Member-restricted link:

<a href="{exp:cartthrob:get_download_link file='/var/www/html/themes/user/cartthrob/images/cartthrob_logo_bg.jpg' member_id='{logged_in_member_id}'}">Download file</a>

Group/role-token link:

<a href="{exp:cartthrob:get_download_link file='/var/www/html/themes/user/cartthrob/images/cartthrob_logo_bg.jpg' group_id='3'}">Download file (group restricted)</a>

Debug file resolution:

{exp:cartthrob:get_download_link file='/var/www/html/themes/user/cartthrob/images/cartthrob_logo_bg.jpg' debug='yes'}