<?php
/**
* ---------------------------------------------------------------------------------
*
* This file is part of the 'giftonordermodule' module feature (main || related module)
* Developped for Prestashop platform.
* You are not allowed to use it on several site
* You are not allowed to redistribute this module
* This header must not be removed
*
* @category  giftonordermodule
* @author    OleaCorner <contact@oleacorner.com> <www.oleacorner.com>
* @copyright OleaCorner
* @version   4.3
* @license   XXX
*         
* ---------------------------------------------------------------------------------
*/

include (dirname (__FILE__).'/../../config/config.inc.php');
include (dirname (__FILE__).'/../../init.php');

if (Tools::getValue ('file'))
{
	/* Admin can directly access to file */
	$filename = Tools::getValue ('file');
	$file = _PS_ROOT_DIR_.$filename;
	if (Tools::file_exists ($file))
	{
		
		/* Detect mime content type */
		$mime_type = false;
		if (function_exists ('finfo_open'))
		{
			$finfo = @finfo_open (FILEINFO_MIME);
			$mime_type = @finfo_file ($finfo, $file);
			@finfo_close ($finfo);
		}
		elseif (function_exists ('mime_content_type'))
			$mime_type = @mime_content_type ($file);
		/*elseif (function_exists ('exec'))
			$mime_type = trim (@exec ('file -bi '.escapeshellarg ($file)));*/
			/* Set headers for download */
		header ('Content-Transfer-Encoding: binary');
		if ($mime_type)
			header ('Content-Type: '.$mime_type);
		header ('Content-Length: '.filesize ($file));
		header ('Content-Disposition: attachment; filename="'.basename ($filename).'"');
		readfile ($file);
	}
}
else
	Tools::d ('ERROR');
exit ();
