<?php

class FileController extends Zend_Controller_Action {
	private $_dir;
	private $_name;
	private $_file;
	
	public function init() {
		$this->_name = $this->getRequest()->getParam('name');
		$this->_dir = APPLICATION_PATH.'/upload_files/';
		
		$this->_file = $this->_dir.$this->_name;
	}
	
	public function downloadAction() {
		$this->getHelper('ViewRenderer')->setNoRender();
		$this->getHelper('layout')->disableLayout();
		
		if (file_exists($this->_file)) {
			header("Content-Type: application/save");
			header("Content-Length:".filesize($this->_name)); 
			header("Content-Disposition: attachment; filename={$this->_name}"); 
			header("Content-Transfer-Encoding: binary");
			header('Expires: 0'); 
			header('Pragma: no-cache');
			
			print file_get_contents($this->_file);
		}
	}
	
	public function viewAction() {
		$this->getHelper('ViewRenderer')->setNoRender();
		$this->getHelper('layout')->disableLayout();
		
		if (file_exists($this->_file)) {
			print file_get_contents($this->_file);
		}
	}
	
	public function croquiAction() {
		$this->getHelper('ViewRenderer')->setNoRender();
		$this->getHelper('layout')->disableLayout();
		
		if (file_exists($this->_file)) {
			print file_get_contents($this->_file);
		}
		
		//print_r($this->getRequest()->getParams());
		//die();
	}
	
}