• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Send ZIP File to Browser

R

ragtek

Guest
#1
How can i send a zipfile from the server to the browser?

Are there any XenForo methods for this?
NOrmaly i would use header(...) but it's not working
 

Shadab

Well-known member
#2
From inside the xenforo framework?

Take a look at the how xenforo handles attachment viewing, to get the idea. Specifically these two classes: XenForo_ControllerPublic_Attachment, and XenForo_ViewPublic_Attachment_View. Heres some sample code:

PHP:
/* In your Controller: */

public function actionIndex()
{
	// Check the viewing user's permission.
	// Check if the zip file is accessible.
	// Any other check you want to perform.

	// Fetch the $zip file info (from db?).

	$this->_routeMatch->setResponseType('raw');

	$viewParams = array(
		'download_name' => 'ragtek.zip',
		'file_path'     => $zip['file_path'],
		'file_size'     => $zip['file_size']
	);

	return $this->responseView('Your_View_File', '', $viewParams);
}
PHP:
/* In your View: */

public function renderRaw()
{
	$this->_response->setHeader('Content-type', 'application/zip', true);
	$this->_response->setHeader('Content-length', $this->_params['file_size']);

	$this->setDownloadFileName($this->_params['download_name']);

	return file_get_contents($this->_params['file_path']);
}
 
R

ragtek

Guest
#3
Oh man, i've forgotten that i could check the attachment code for this:D


thx very much, it's working great.
I hope that my add-on package builder can be released soon