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

General project discussion. NOT for help questions.
Post Reply
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

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

Post 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
Last edited by piotrekkr on Mon Jul 30, 2007 7:26 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

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

Post 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 :(
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post 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(); }
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

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

Post by piotrekkr »

Code: Select all

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

Return to “General Discussion”