Page 1 of 1

[solved]problem with download script (something wron with output buffering)

Posted: Mon Jul 30, 2007 4:34 pm
by piotrekkr
Hi.
I'm making module and I have there action to download a file from serwer (action.get_prof_file.php).

Code: Select all

..................
if(ini_get('zlib.output_compression')){
		ini_set('zlib.output_compression', 'Off');
	}
	@ob_clean();
	@ob_clean();
	if(!file_exists($file_path) || !is_readable($file_path)) die("File can't be readable");
	header('Pragma: public');
	header('Expires: 0');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Cache-Control: private',false);
	header('Content-Description: File Transfer');
	header('Content-Type: application/force-download');
	header('Content-Length: '.filesize($file_path));
	header('Content-Disposition: attachment; filename="'.$row['oryginal_name'].'"');
	readfile($file_path);
	exit;
Every file I downloaded using this script contain some part of html code of my page but file i uploaded are normal files not html code. I really don't know what's wrong. I tried to clear outpu buffer but this didn't make any changes :/ pls help

PS. path to downloaded file (in $file_path variable) is correct and file exists and is readable. This part of code is mostly copied fromĀ  Uploads module and in upload module download works perfect.

PS2 sorry for my poor english

Re: problem with download script (something wron with output buffering)

Posted: Mon Jul 30, 2007 5:57 pm
by calguy1000
The uploads module uses a while loop to clean out the output buffer.... maybe you should use that.

Also, you'll need the show_template=false parameter on the link that leads to that code.

Re: problem with download script (something wron with output buffering)

Posted: Mon Jul 30, 2007 7:12 pm
by piotrekkr
What do you mean by
The uploads module uses a while loop to clean out the output buffer.... maybe you should use that.
can you tell me where is that loop in which file? I can't see it in module code.
and this
Also, you'll need the show_template=false parameter on the link that leads to that code.
you mean to use it in CreateLink() as array('show_template' => 'false') or as array('show_template' => 0) or maby in another way??
I tried this two ways and it didn't work :(

Re: problem with download script (something wron with output buffering)

Posted: Mon Jul 30, 2007 7:17 pm
by calguy1000
in the params for the link add:
'showtemplate'=>'false'

also...
This is the code that Uploads is using for cleaning buffers:

Code: Select all

for ($cnt = 0; $cnt < sizeof($handlers); $cnt++) { ob_end_clean(); }

Re: problem with download script (something wron with output buffering)

Posted: Mon Jul 30, 2007 7:20 pm
by piotrekkr

Code: Select all

array('showtemplate' => 'false')'
Ok it works great! Thanks!