<?php
set_time_limit(0);

function file_output($fileinfo,$speed,$ad)
{
	$filepath = $fileinfo['path'];
	$filename = iconv("UTF-8","GBK",$fileinfo['name']);
	$ad=iconv("UTF-8","GBK",$ad);
	header('Cache-control: private');
    header('Content-type: application/force-download');
    header('Content-Length: ' . filesize($filepath));
    header('Content-Disposition: attachment; filename="'.$ad.$filename.'"'); 
	if (!$file = fopen($filepath, 'rb')){exit;}
	$times = ($speed * 1024)/8192;
    while (!feof($file)) 
	{
		$i = 0;
		while($i < $times)
		{
            echo fread($file, 8192);
			$i =$i+1;
		}
		unset($i);
	   ob_flush();
       flush();
       sleep(1);
    }
}

function check_code($code)
{
	if(preg_match("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",$code)){return false;}
	if(strlen($code) != 22){return false;}
	return true;
}

function get_code_info($code)
{
	$a['id']  = substr($code,0,12) ;
	$a['time']= substr($code,12,10);
	return $a;
}

function make_path($id)
 {
	 $time = substr($id,2,10);
	 $dp   = date('ym',$time);
	 $path = "./file/$dp/$id.data";
	 return $path;
 }
?>