<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

</head>

<body>

<?

require_once("../../include/config.php");

require_once("../admin_loginstate.php");

$sort=12;

$f_type=strtolower("mp3,wma,flv,mp4,swf");//设置可上传的文件类型 

$file_size_max=200*1024*1024;//限制单个文件上传最大容量 

$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许 

$f_input="Files";//设置上传域名称

    foreach($_FILES[$f_input]["error"] as $key => $error){ 

        $up_error="no"; 

        if ($error == UPLOAD_ERR_OK){ 

            $f_name=$_FILES[$f_input]['name'][$key];//获取上传源文件名 

			

            $uploadfile=$uploaddir.strtolower(basename($f_name)); 

             

            $tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名

			$tmp_type=strtolower($tmp_type); 

            if(!stristr($f_type,$tmp_type)){ 

                echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>"; 

                $up_error="yes"; 

            }              



            if ($_FILES[$f_input]['size'][$key]>$file_size_max) { 

			

                echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_FILES[$f_input]['size'][$key]/1024)."Kb,大于规定的".($file_size_max/1024)."Kb,上传失败!')</script>"; 

                $up_error="yes"; 

            } 

             

            if (file_exists($uploadfile)&&!$overwrite){ 

                echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>"; 

                $up_error="yes"; 

            } 

             $string = 'abcdefghijklmnopgrstuvwxyz0123456789';

$rand = '';

for ($x=0;$x<12;$x++)

 $rand .= substr($string,mt_rand(0,strlen($string)-1),1);

 $nowdate="../../upload/url/".date('Ymd');	 //按日期创建文件夹

      if(!file_exists($nowdate)){

	    @mkdir($nowdate,0777);

      }

      if(file_exists($nowdate)){

	     $datefolder=date('Ymd')."/";

      }else{

	    $datefolder='/';

      }

//$t=date("ymdHis").substr($gettime[0],2,6).$rand.".".$tmp_type;//修改文件名

$t=$datefolder.$f_name;//使用默认的文件名

$attdir="../../upload/url/"; //保存文件夹

    if(!is_dir($attdir))   

    {  mkdir($attdir);}

            $uploadfile=$attdir.$t; 

            if(($up_error!="yes") and (move_uploaded_file($_FILES[$f_input]['tmp_name'][$key], $uploadfile))){ 

                        $tpyz=file_type($uploadfile);

			if(($tpyz!="mp3") && ($tpyz!="wma") && ($tpyz!="flv") && ($tpyz!="mp4") && ($tpyz!="swf"))    

			{   

 			   unlink($uploadfile);   

			  $_msg='上传文件类型不正确,上传失败\n';

			  echo "<script>window.parent.Finish('".$_msg."','');</script>";

			}else{ 

			  $_msg='恭喜您,上传成功\n';

			  echo "<script>window.parent.Finish('".$_msg."','".S_SitePath."upload/url/".$t."')</script>";

                        }

                 		

            } 

			else{

			$_msg='上传失败\n';

			echo "<script>window.parent.Finish('".$_msg."','');</script>";

			}

        } 

	

    } 	



//判断类型

function file_type($filename)   

{   

    $file = fopen($filename, "rb");   

    $bin = fread($file, 2); //只读2字节   

    fclose($file);   

    $strInfo = @unpack("C2chars", $bin);   

    $typeCode = intval($strInfo['chars1'].$strInfo['chars2']);   

    $fileType = '';   

    switch ($typeCode)   

    {   

        case 4838:   

            $fileType = 'wma';   

            break; 

        case 7368:   

            $fileType = 'mp3';   

        case 0:   

            $fileType = 'flv';   

            break;   

        case 6787:   

            $fileType = 'swf';   

            break;  

        default:   

            $fileType = 'no';   

    }   

    return $fileType;   

} 

?>

</body>

</html>

