<?php
/**
 * Front-end wrapper for downloading files that were uploaded in the CMS
 * Has support for conditional get and partial downloads. Both require HTTP/1.1,
 * but the script is backwards compatible with HTTP/1.0
 * @author Erik Hoogeboom
 * @version $Id: file.php5,v 1.8 2009-03-11 15:41:51 hoogeboom Exp $
 * @package egrip
 */

require_once("VWM/VWM.php");

// get VWM instance
$vwm = VWM::getInstance('../../vwm_config.xml');

// load CMS dataobjects ini
VWM_Controller::loadDataObjectsfiles('CMS');

require_once('CMS/CMS_File.class.php');

if ($file_id = $_REQUEST['id']) {
    $tmp_file = new CMS_File();
    $tmp_file->setid($file_id);
    if ($tmp_file->find(true)) {

        $filename = $tmp_file->getdata_dir().$tmp_file->getsystemfilename();

		require_once('VWM/util/VWM_FileServer.class.php');
		$fileServer = new VWM_FileServer($filename, null, $tmp_file->getmimetype());
		$fileServer->setDisposition('attachment', $tmp_file->getDownloadFilename());
		$fileServer->doServe($_SERVER);
		exit;
	}

}
?>
