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:
- download_file_form
- get_download_link
view_download_link(code-available legacy helper;tags_detailpage not yet created)- downloads tag index
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
- If
fieldandentry_idare provided, the tag fetches that entry and tries to resolve the field value into a file path. - If
member_idis 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
- If no file is available after resolution, the tag returns a
download_url_not_specifiederror. - If
encrypted="yes", thefilevalue is decoded before download is attempted. - The tag calls
cartthrob_file->force_download(...). - If the file layer returns errors, the tag outputs an error.
- 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_formorget_download_linkfor 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}"}