Download file control [message #211] |
Wed, 26 July 2006 01:53 |
ljkbrost
Messages: 59 Registered: April 2006
|
Member |
|
|
Working with the framework I have created the support for downloading a file from the system without exposing the location of the file.
I have created a std.filedownload1.inc that will download a single file based on the the selection passed in from the previous screen. The system checks that the selected record exists and then expects the cm_post_getData class to add the following keys.
download_filename - The absolute path to the file
download_filetype - The mime type of the file being downloaded
download_mode - [inline|attachment] if the mode is 'inline' the file is opened in the current browser. If the file is attachment it causes the browser to pop-up an attachment save-as screen.
After getting the download_* fields it verifies the information and then spools the file to the client. After spooling the file it calls the updateRecord to inform the caller that it is complete. The update process is wrapped in a transaction to ensure that if the upload fails the update is rolled back (transaction code currently commented out).
Example:
The following function are in the class file that needs to support the downloading of files. The _cm_post_getData(...) adds the required download_* fields and the _cm_pre_updateRecord(...) updates a field to record the date the file was downloaded.
report.class.inc:
function _cm_post_getData ($rowdata, &$where)
// perform custom processing after database record(s) are retrieved.
// NOTE: $where is passed BY REFERENCE so that it may be modified.
{
if(strstr($_SERVER['PHP_SELF'],"report_download2.php"))
{
for($theIndex=0;$theIndex<sizeof($rowdata);$theIndex++)
{
$rowdata[$theIndex]['download_filename'] = $rowdata[$theIndex]['report_file'];
$rowdata[$theIndex]['download_mode'] = 'attachment';
if(strstr($rowdata[$theIndex]['download_filename'], ".pdf"))
{
$rowdata[$theIndex]['download_filetype'] = "application/pdf";
}
else if(strstr($rowdata[$theIndex]['download_filename'], ".xls"))
{
$rowdata[$theIndex]['download_filetype'] = "application/vnd.ms-excel";
}
}
}
return $rowdata;
}
function _cm_pre_updateRecord ($rowdata)
// perform custom processing before database record is updated.
// errors are added to $this->errors.
{
if(strstr($_SERVER['PHP_SELF'],"report_download2.php"))
{
for($theIndex=0;$theIndex<sizeof($rowdata);$theIndex++)
{
$rowdata[$theIndex]['report_download'] = strftime("%Y-%m-%d", mktime());
}
}
return $rowdata;
} // _cm_pre_updateRecord
report_download2.php (the control file):
<?php
$table_id = "report";
require_once "std.filedownload1.inc";
?>
std.filedownload1.inc (attached)
|
|
|
|
Re: Download file control [message #215 is a reply to message #214] |
Wed, 26 July 2006 12:35 |
AJM
Messages: 2363 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
The following has been coded and tested and will be available in the next release:
- File /includes/std.filedownload1.inc which is the standard controller for this pattern.
- File /xample/person_filedownload.php which uses the new controller. This can be accessed from a navigation button in the "Enquire Person" screen.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|