<?php
error_reporting(0);
include "../../include/cctvai.conn.php";
$id=SafeRequest("id", "get");
$action=SafeRequest("ac", "get");
switch ($action) {
	case 'malbum':
		$targetFiles="../../upload/malbum/a/" . date('Ymd') . "/" . $id . "." . fileext($_FILES['Filedata']['name']);
		$m="upload/malbum/a/" . date('Ymd') . "";
		$fileexts=cd_uppictype;
		$filetypes="音乐专辑图片";
		break;
	case 'valbum':
		$targetFiles="../../upload/valbum/a/" . date('Ymd') . "/" . $id . "." . fileext($_FILES['Filedata']['name']);
		$m="upload/valbum/a/" . date('Ymd') . "";
		$fileexts=cd_uppictype;
		$filetypes="视频专辑图片";
		break;
	case 'singer':
		$targetFiles="../../upload/artist/" . date('Ymd') . "/" . $id . "." . fileext($_FILES['Filedata']['name']);
		$m="upload/artist/" . date('Ymd') . "";
		$fileexts=cd_uppictype;
		$filetypes="歌手图片";
		break;
	case 'videopic':
		$targetFiles="../../upload/videopic/a/" . date('Ymd') . "/" . $id . "." . fileext($_FILES['Filedata']['name']);
		$m="upload/videopic/a/" . date('Ymd') . "";
		$fileexts=cd_uppictype;
		$filetypes="视频图片";
		break;
	case 'dancepic':
		$targetFiles="../../upload/dancepic/a/" . date('Ymd') . "/" . $id . "." . fileext($_FILES['Filedata']['name']);
		$m="upload/dancepic/a/" . date('Ymd') . "";
		$fileexts=cd_uppictype;
		$filetypes="音乐图片";
		break;
	case 'dance':
		$targetFiles="../../upload/dance/a/" . date('Ymd') . "/" . $id . "." . fileext($_FILES['Filedata']['name']);
		$m="upload/dance/a/" . date('Ymd') . "";
		$fileexts=cd_upmusictype;
		$filetypes="音乐文件";
		break;
	case 'video':
		$targetFiles="../../upload/video/a/" . date('Ymd') . "/" . $id . "." . fileext($_FILES['Filedata']['name']);
		$m="upload/video/a/" . date('Ymd') . "";
		$fileexts=cd_upvideotype;
		$filetypes="视频文件";
		break;
}
if (!empty($_FILES)) {
	//检查文件格式
	if (strpos($fileexts, fileext($_FILES['Filedata']['name']))!==false) {
	} else {
	@unlink($_FILES['Filedata']['tmp_name']);
		exit('1');
	}
	//创建文件夹
	$dir=_cctvai_root_ . $m;
	if (!file_exists($dir)) {
		@mkdir($dir, 0777, true);
	}
	//写入文件
	$tempFile=$_FILES['Filedata']['tmp_name']; //临时目录
	if (move_uploaded_file($tempFile, $targetFiles)===false) {
		exit('5');
	}
	@chmod($targetFiles, 0644); //设置权限
	//记录上传信息
	$setarrss=array(
		'cd_userid' => 0,
		'cd_username' => '后台用户',
		'cd_userip' => $_SERVER["REMOTE_ADDR"],
		'cd_filetype' => $filetypes,
		'cd_filename' => $id . "." . fileext($_FILES['Filedata']['name']),
		'cd_filesize' => $_FILES["Filedata"]["size"],
		'cd_fileurl' => ReplaceStr($targetFile, "../../", ""),
		'cd_filetime' => time()
	);
	inserttable('upload', $setarrss, 1);
	echo '0';
}
?>