Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » RADICORE Suggestions » Download file control
Download file control [message #211] Wed, 26 July 2006 01:53 Go to next message
ljkbrost is currently offline  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 #214 is a reply to message #211] Wed, 26 July 2006 05:02 Go to previous messageGo to next message
AJM is currently online  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
Interesting. I'll take a look at it and see if I can include it in the next release.

Re: Download file control [message #215 is a reply to message #214] Wed, 26 July 2006 12:35 Go to previous message
AJM is currently online  AJM
Messages: 2367
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.


Previous Topic: Selecting specific databases instead of all.
Next Topic: component scripts
Goto Forum:
  


Current Time: Sat Nov 23 04:48:07 EST 2024

Total time taken to generate the page: 0.01177 seconds