<?php
require dirname(__FILE__) . "/dzsck.php";

/*$upfile = $_FILES['upfile'];  本地视频上传
function upload_file($files, $path = "../shootingimg/video",$imagesExt=['jpg','png','jpeg','gif','mp4']){
    // 判断错误号
    if (@$files['error'] == 00) {
        // 判断文件类型
        $ext = strtolower(pathinfo(@$files['name'],PATHINFO_EXTENSION));
        if (!in_array($ext,$imagesExt)){
            return "非法文件类型";
        }
        // 判断是否存在上传到的目录
        if (!is_dir($path)){
            mkdir($path,0777,true);
        }
        // 生成唯一的文件名
        $fileName = md5(uniqid(microtime(true),true)).'.'.$ext;
        // 将文件名拼接到指定的目录下
        $destName = $path."/".$fileName;
        // 进行文件移动
        if (!move_uploaded_file($files['tmp_name'],$destName)){
            return "文件上传失败！";
        }
        return $destName;
    } else {
        // 根据错误号返回提示信息
        switch (@$files['error']) {
            case 1:
                echo "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值";
                break;
            case 2:
                echo "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值";
                break;
            case 3:
                echo "文件只有部分被上传";
                break;
            case 6:
            case 7:
                echo "系统错误";
                break;
        }

    }

}*/

/** 本地图片上传 **/
$file = $_FILES['file'];
function upload_file2($files, $path = "../shootingimg/images",$imagesExt=['jpg','png','jpeg','gif']){
    // 判断错误号
    if (@$files['error'] == 00) {
        // 判断文件类型
        $ext = strtolower(pathinfo(@$files['name'],PATHINFO_EXTENSION));
        if (!in_array($ext,$imagesExt)){
            return "非法文件类型";
        }
        // 判断是否存在上传到的目录
        if (!is_dir($path)){
            mkdir($path,0777,true);
        }
        // 生成唯一的文件名
        $fileName = md5(uniqid(microtime(true),true)).'.'.$ext;
        // 将文件名拼接到指定的目录下
        $destName = $path."/".$fileName;
        // 进行文件移动
        if (!move_uploaded_file($files['tmp_name'],$destName)){
            return "文件上传失败！";
        }
        return $destName;
    } else {
        // 根据错误号返回提示信息
        switch (@$files['error']) {
            case 1:
                echo "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值";
                break;
            case 2:
                echo "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值";
                break;
            case 3:
                echo "文件只有部分被上传";
                break;
            case 6:
            case 7:
                echo "系统错误";
                break;
        }

    }

}

if (($_GET["type"] == "add") && $_POST) {
	$time = time();  
	$url2 = $_POST["upfile2"];
	$pic2 = $_POST["file2"];
	$pic = upload_file2($file);
	if($pic == null){
		$pic = $pic2;
	}
	$date = array(
		"s_name" => $_POST["s_name"],
		"s_pic" => $pic,
		"s_url" => $url2,
		"s_content" => $_POST["s_content"],
		"s_time" => $time
	);
		
	$updates = $cm->cmadd($date,"d_shooting");
	if($updates){
		echo tiao("添加成功！", "shooting.php");
		exit();
	}else{
		echo tiao("添加失败,请重新添加！", "addshooting.php");
		exit();
	} 
		
}



?>
<!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="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加影视</title>
<link href="public/css/base.css" rel="stylesheet" type="text/css" />
<link href="public/css/style.css" rel="stylesheet" type="text/css" />

<style type="text/css">
        #myEditor{
            width: 600px;
            height: 180px;
        }
		#myEditor1{
            width: 600px;
            height: 180px;
        }
</style>
</head>
<body>
<div class="tab" id="tab"> <a class="selected" href="#">添加影视</a></div>
<div class="page_form">
<form name="form2" method="post" action="?type=add" enctype="multipart/form-data">
<div class="page_table form_table">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        
   
        <tr>
			<td width="132" align="right">影视名</td>
			<td width="500">
				<input type="text" name="s_name" />
			</td>
		</tr>
		<tr>
			<td width="132" align="right">影视封面图</td>
			<td width="385">
				<input type="hidden" name="MAX_FILE_SIZE" value="2000000000">
				<input name="file" type="file" />
			</td>
		</tr>
		<tr>
			<td width="132" align="right">影视外部封面图</td>
			<td width="385">
				<input name="file2" type="text" />注：已上传封面图外部封面图可不填
			</td>
		</tr>
		
		<tr>
			<td width="132" align="right">影视外部视频</td>
			<td width="385">
				<input type="text" name="upfile2" />填写视频绝对文件地址，支持.MP4、.m3u8格式<!--注：已上传视频外部视频可不填-->
			</td>
		</tr>
		<tr>
			<td width="132" align="right">影视简介</td>
			<td width="385">
				<textarea name="s_content"></textarea>
			</td>
		</tr>
    </table>
</div>
<!--普通提交-->
<div class="form_submit">
<button type="submit" class="button">添加</button> 
</div>
</form>
</div>
</div>
<div class="fn_clear"></div>
</body>
</html>