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

Download File

A video tutorial on this download flow is available..

download_file is an immediate-execution tag that attempts to deliver a file directly when the template renders.

This is a legacy/direct download pattern. For most current implementations, use download_file_form or get_download_link.

See also:

Parameters

file

Direct file path/URL source for download.

This is required unless a file path is resolved via field + entry_id.

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

field

Channel field short name that contains the file path.

Use with entry_id.

field="product_download_url"

entry_id

Entry ID used with field to resolve the file path.

If field + entry_id resolves successfully, that resolved path is used as file.

entry_id="123"

member_id

Optional member restriction.

When provided, the current logged-in member ID must match this value (or decoded value when encrypted="yes" is used).

member_id="{logged_in_member_id}"

encrypted

When truthy, this tag decodes file and member_id before using them.

This is mainly used in legacy flows where encoded values are passed in URL segments.

encrypted="yes"

Behavior and Constraints

  1. If field and entry_id are provided, the tag fetches that entry and tries to resolve the field value into a file path.
  2. If member_id is provided, member authorization is enforced:
    • empty/invalid member ID value results in a not-authorized error
    • with encrypted="yes", decoded member ID must match the current member ID
  3. If no file is available after resolution, the tag returns a download_url_not_specified error.
  4. If encrypted="yes", the file value is decoded before download is attempted.
  5. The tag calls cartthrob_file->force_download(...).
  6. If the file layer returns errors, the tag outputs an error.
  7. On success, output is file delivery (not normal page/template text output).

Notes:

  • This is not a form tag.
  • This tag does not document group-based restriction behavior. Group/role restriction workflows are handled in link/form download flows.
  • This is a legacy helper; prefer download_file_form or get_download_link for current templates.

Examples

Basic direct file download:

{exp:cartthrob:download_file file="/var/www/html/themes/user/cartthrob/images/cartthrob_logo_bg.jpg"}

Resolve file from entry field:

{exp:cartthrob:download_file entry_id="{entry_id}" field="product_download_url"}

Legacy encrypted URL-segment flow (software-download tutorial pattern):

{if segment_2=="download_file"}
    {exp:cartthrob:download_file encrypted="yes" file="{segment_3}" member_id="{segment_4}"}
{/if}

Member-restricted direct usage:

{exp:cartthrob:download_file file="/var/www/html/themes/user/cartthrob/images/cartthrob_logo_bg.jpg" member_id="{logged_in_member_id}"}