[ic] Sending a (Binary) File to the User

Stefan Hornburg racke at linuxia.de
Thu Aug 25 08:20:13 EDT 2005


On Wed, 24 Aug 2005 15:41:24 -0700
"Andrew Shelansky" <andrew at lunsfordgroup.com> wrote:

> Hello Interchange folks,
>  
> I'm trying to implement a downloadable-products feature... and I've hit a simple snag...
>  
> I know how to handle everything on the order / payment front, and even have a setup that lets a user request a download.  I have an action that can tell that they either are or are not entitled to the file.
>  
> But I can't figure out how to make Interchange return the file (instead of showing a normal page).
>  
> At first I tinkered with the file tag... tried making my page be just a one-line [file name="[scratch filename]"] call... but that didn't do anything at all...
>  
> I can have the action load the file and put it in a scratch variable or something... just need help getting the file out to the user...

The deliver tag is your friend, example usage:

ActionMap download <<EOM
sub {
	my ($name, $type, $project, $id, $file) = split('/', shift);
	my ($ref, $ret);

	$Tag->perl({tables => 'iso_matrix'});

	if ($ref = $Db{iso_matrix}->row_hash($id)) {
		if ($type eq 'flowchart') {
			$ret = $Tag->deliver({file => "matrix/$project/$id-fc/$ref->{upload_flowchart}"});
		} else {
			$ret = $Tag->deliver({file => "matrix/$project/$id/$ref->{upload_file}"});
		}
		return;
	}

	Log ("No document found $name $type $project $id $file");
	$CGI->{mv_nextpage} = 'matrix';
	return 1;
}
EOM

Please not there is no protection of the download against unauthorized access in this example.

Bye
	Racke

-- 
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team



More information about the interchange-users mailing list