Skip to content
  1. Extras
  2. FileAttach

FileAttach

Module for uploading files to resources in the site manager.

  • Access to upload and download can be restricted with access policies;
  • Administrative management of all uploaded files on the site;
  • A media source is available for browsing uploaded files (when the package is registered globally during installation);
  • File list is stored in a database table.

For each file you can set a description, privacy mode (direct link access), download count, and SHA1 checksum.

Files can be downloaded via direct link. "Private" files get a long generated name that does not match the original filename. "Public" files keep their original name.

You can reorder files by dragging entries in the editor.

Supports MySQL and SQLSrv.

Development: https://github.com/13hakta/FileAttach

Chunk FileAttachTpl

Defines how file entries are rendered.

NameDescription
&descriptionDescription
&docidResource ID the file is attached to
&downloadDownload count
&hashSHA1 checksum
&idFile ID
&internal_nameInternal name (filename on the filesystem)
&nameFile name (same as internal_name when private=no)
&pathPath within the media source
&privateWhether the file is private
&rankSort order in the list
&sizeFile size in bytes

Default chunk content:

modx
<p>[[+description:notempty=`<strong>[[+description]]</strong><br/>`]]
<a href="[[+url]]">[[+name]]</a> <span class="badge">[[+download]]</span>
[[+size:notempty=`<br/><small>Size: [[+size]] bytes</small>`]]
[[+hash:notempty=`<br/><small>SHA1: [[+hash]]</small>`]]</p>

Snippet FileAttach

Outputs the list of files.

NameDefaultDescription
&limit0Max number of files to output (0 = all)
&makeURLfalseGenerate download link for the file
&outputSeparatorSeparator between output entries
&privateUrlfalseForce download via connector (counts downloads for public files too)
&resource0Resource ID to show files for (0 = current resource)
&showSizefalseInclude file size
&sortBynameSort by field
&sortDirASCSort direction
&toPlaceholderfalseStore result in a placeholder instead of outputting
&tplFileAttachTplChunk for each file row

Class FileItem

Methods

NameDescriptionParameters
generateNameGenerate a new file namelength (int) = 32
getFullPathGet full path to the file
getPathGet path relative to media source root
getSizeGet file size
getUrlGet file URL
renameRename the filename (str)
sanitizeNameSanitize invalid characters in the file namename (str)
setPrivateSet privacy modeprivate (bool)

System settings

NameDefaultDescription
calchashfalseCalculate SHA1 checksum on upload
downloadtrueCount downloads
files_pathPathPath relative to media source root (must end with "/")
mediasource1Media source ID
privatefalseMake files private by default on upload
put_docidfalseStore files in a resource subfolder
templatesComma-separated list of document template IDs where the module is active
user_foldersfalseStore files in a user subfolder

Download connector

Private files are downloaded through the connector, which hides the direct file URL and counts downloads. You can also serve public files via the connector by setting &privateUrl=1 in the snippet call; the connector will then redirect to the direct link.

Connector URL format: MODX_ASSETS_URL/components/fileattach/connector.php?action=web/download&ctx=web&id=file_id, where file_id is the file ID in the database.

Access policies

Permissions

NameDescription
fileattach.doclistManage files in a document
fileattach.downloadDownload files
fileattach.totallistManage all files

Usage example

Simple call:

modx
[[FileAttach]]

To count downloads for all files, use the private URL:

modx
[[FileAttach? &privateUrl=`1`]]

Sort by manual order:

modx
[[FileAttach? &sortby=`rank`]]

Screenshots

  • File list in the manager

    File list in the manager

  • Media source tree

    Media source tree

  • File editing

    File editing

  • File editing in admin mode

    File editing in admin mode

  • File list on the front-end

    File list on the front-end

  • Upload dialog

    Upload dialog