<?php 
session_start();

$filedir = "distributors/"; 
$file = $_POST["file"];
$submit = $_POST["submit"];

/*
//$uservalidated = true;
if (false)
{
	header("location: distrilogin.php");
	echo "you must <a href=login.php>login</a> to download files";
}
*/

if ($submit == "Save") 
{ 
	$file_actual_name=$filedir.rawurldecode($file); 
	// Filename may not contain a slash 
	
	if (isset($file) && !strpos($file,"/") && file_exists($file_actual_name)) 
	{ 
		$fp=fopen($file_actual_name,"r"); 
		$body = fread($fp, filesize($file_actual_name)); 
		fclose($fp); 
		header("Content-Type: application/octet-stream"); 
		//Header("Content-type: $mime_type; name=$file"); 
		Header("content-disposition: attachment; filename=$file");
		header("Cache-Control: no-store, no-cache, must-revalidate");
          	header("Cache-Control: post-check=0, pre-check=0", false);
          	header("Pragma: no-cache");
          	header("Cache-control: private");
		echo $body;
	} 
}
else
{
	$file_actual_name=$filedir.rawurldecode($file); 
	// Filename may not contain a slash 
	
	if (isset($file) && !strpos($file,"/") && file_exists($file_actual_name)) 
	{ 
		$fp=fopen($file_actual_name,"r"); 
		$body = fread($fp, filesize($file_actual_name)); 
		fclose($fp); 
		header("Content-Type: application/octet-stream"); 
		//Header("Content-type: $mime_type; name=$file"); 
		Header("content-disposition: inline; filename=$file");
		header("Cache-Control: no-store, no-cache, must-revalidate");
          	header("Cache-Control: post-check=0, pre-check=0", false);
          	header("Pragma: no-cache");
          	header("Cache-control: private");
		echo $body; 
	}
}
?> 