Skip to content

Controller

sendFile()

sendFile() — returns any

Available in: controller Category: Miscellaneous Functions

Sends a file to the user (from the files folder or a path relative to it by default).

NameTypeRequiredDefaultDescription
filestringyes—The file to send to the user, relative to the filePath folder on disk (public/files by default; subfolders such as reports/2026/q1.zip are fine). Values containing the .. character sequence anywhere (even as part of a legitimate file name) are rejected to prevent path traversal.
namestringno—The file name to show in the browser download dialog box.
typestringno—The HTTP content type to deliver the file as.
dispositionstringnoattachmentSet to inline to have the browser handle the opening of the file (possibly inline in the browser) or set to attachment to force a download dialog box.
directorystringno—Directory outside of the web root where the file exists. Must be a full path. Values containing the .. character sequence are rejected to prevent path traversal.
deleteFilebooleannofalsePass in true to delete the file on the server after sending it.
deliverbooleannotrueWhen set to false, the file will not be sent to the browser (used for testing).
// 1. Send a PDF file to the user from the default files folder
sendFile(file="wheels_tutorial_20081028_J657D6HX.pdf");

// 2. Send the same file but give the user a friendlier name in the browser download dialog
sendFile(file="wheels_tutorial_20081028_J657D6HX.pdf", name="Tutorial.pdf");

// 3. Display the file inline in the browser instead of forcing a download dialog
sendFile(file="report.pdf", disposition="inline");

// 4. Send a file with an explicit MIME type
sendFile(file="export.csv", type="text/csv", name="data-export.csv");

// 5. Send a file located outside of the web root using an absolute directory path
sendFile(file="invoice_2024_001.pdf", directory="/var/app/private/invoices");

// 6. Send a file and delete it from the server after delivery (e.g., a temporary export)
sendFile(file="temp_export_J657D6HX.csv", name="export.csv", deleteFile=true);

// 7. Send a file stored in the RAM virtual file system
sendFile(file="ram://generated_report.pdf", name="report.pdf");