Send ZIP File to Browser

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
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
 
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']);
}
 
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
 
Top Bottom