- ^ Main concepts
- ^ Responses: generating content
Section: Sending a binary file
|« Generating PDF with TCPDF||^ Responses: generating content||Generating a ZIP file »|
To send binary content to the user (a graphic, a video, some sound, an archive, etc.),
jResponseBinary should be used. To use it, set 'binary' as the type of response used.
$resp = $this->getResponse('binary');
Afterwards, some variables need to be set to a correct value before content is displayed.
First, you have to set
outputFileName will be the name shown to the user.
$resp->outputFileName = 'filename.gif';
Next, you can define the mime type of your content:
$resp->mimeType = 'image/gif';
You have an option for files you want the user to download (particularly, files not rendered by common browsers - archives, for example). To force the download of the file, simple set
doDownload to true.
$resp->doDownload = true;
For the content itself, you have to define either
If it is an existing file, just use
$resp->fileName = jApp::varPath('file_to_send.gif');
Otherwise, if your content is generated or comes from your database, use
$resp->content = '...';