Howto send a file to the user (showing save file dialog)

marcusx 09 Oct, 2008
Hi!

Can anyone tell me how to send a csv file to the user by showing the save file dialog? I try something like this.


 $fd = @fopen( $realfilename, "r" ) or die ( "Cannot open file" );

 header("Content-Disposition: attachment; filename=$file");
 header("Content-Type: application/zip");   // filetype
 header("Content-Length: ".filesize( $realfilename )); // filesize
 header("Pragma: no-cache");
 header("Expires: 0");

 // send
 fpassthru( $fd );
 fclose( $fd );
 exit();



I think it's because cf sends another header bevore my code, because I have all the cf code in a blank page. How can I avoid this?

cheers
marcus
Max_admin 09 Oct, 2008
Hi,this code does it from the Chronoforms admin functions :

if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
		$UserBrowser = "Opera";
	}
	elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
		$UserBrowser = "IE";
	} else {
		$UserBrowser = '';
	}
	$mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
	@ob_end_clean();
	ob_start();

	header('Content-Type: ' . $mime_type);
	header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');

	if ($UserBrowser == 'IE') {
		header('Content-Disposition: inline; filename="' . $rows[0]->name.'.cfbak"');
		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
		header('Pragma: public');
	}
	else {
		header('Content-Disposition: attachment; filename="' . $rows[0]->name.'.cfbak"');
		header('Pragma: no-cache');
	}
	print $string;
	exit();
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
miki 18 Nov, 2008
Hi guys

First of all thankyou to the developers for the great work you're doing!!!! 😀

I read this topic because I have a similar issue. After someone submits a form I would like him to recieve a pdf file. Using a save file dialog would be great! Now I read this thread but couldn't make out how to make this work. Do I have to insert the code shown somewhere or was that just a hint on where to put in some piece of code to make it work.
Another possibility would be to send the pdf after with a confirmation eMail. Is there a way to do this easily?

Many thanx in advance for helping me :wink: .

Kind regards,
*Miki
GreyHead 18 Nov, 2008
Hi miki,

You'll need to write a code snippet to do this. In the OnSubmit before email box you need to put a valid path to the file in the $attachments array. Any files in this array will be attached to the form emails.

Bob
This topic is locked and no more replies can be posted.