|
$format = array('doc','docx','wps','gif','png','jpg'); //限定上传格式
$category = trim($this->input->post('category')); //类别名称
$contest_name = trim($this->input->post('contest_name')); //赛项名称
$type = trim($this->input->post('type')); //组别
$typenext = trim($this->input->post('typenext')); //组别子类
$begin = trim($this->input->post('begin_time')); //开始时间
$end = trim($this->input->post('end_time')); //结束时间
$content = trim($this->input->post('content')); //内容
$form = $_FILES['myform']; //申报表格
$filename = substr(strrchr($form['name'],"."),1); //获取文件的后缀名 比如png
if(!in_array(strtolower($filename),$format)){ //判断后缀名
echo "<font color='red'>上传文件格式不正确,请重新上传</font>";
}elseif($form['size']>=2000000){
echo "<font color='red'>上传大小超出2M</font>";
}else{
if(!empty($category) && !empty($contest_name)){
$newname = $category.$contest_name.'.'.$filename; //组合成类别名+赛项名
$uri = ROOT_PATH.'uploadfile/file/'.date('Y').'/'.date('m-d').'/';
$upfile = $uri.$newname;
if(!is_dir($uri)){
mkdir($uri,0777, TRUE); //如果没有文件夹就创建
}
$config['allowed_types'] = 'gif|jpg|png|docx|doc|wps'; //这里配置了doc docx 文件格式 可是上传这些文件就是不行,图片是可以的.
$config['upload_path'] = $uri;
$config['file_name'] = date("Ymd His").$newname;
$config['max_size'] = '2048';
$this->load->library('upload', $config);
if($this->upload->do_upload('myform')){
$arr = array('upload_data' => $this->upload->data());
var_dump($arr);
}else{
$arr['error'] = array('error' => $this->upload->display_errors());
var_dump($arr['error']);
}
}
}
|
|