/**
* 单文件上传
* @param array
* @return string
*/
function upload_one($param,$type=0)
{
$upload = new \Think\Upload();
// $upload->maxSize = 2097152; //字节 1KB=1024字节 默认为2M
$upload->maxSize = 102097152; //字节 1KB=1024字节 200M
if($type==1){
//图片和视频
$upload->exts = array('flv','mp4','rmvb','avi','mpeg','ra','ram','mov','wmv');
}elseif($type==2){
$upload->exts = array('mp3', 'wav', 'wma', 'ogg','ape','acc'); //音频
}else{
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');
}
$upload->savePath = $param['savePath']; //保存路径 相对路径
$upload->subName = $param['subName']; //子目录
// $upload->saveName = $param['saveName']; //保存名称
$upload->saveName = array('uniqid',$param['saveName']); //保存名称 (uniqid有重复的可能)
$upload->saveExt = $param['saveExt']; //保存后缀
$upload->replace = true; //存在同名的文件 覆盖
$info = $upload->uploadOne($param['files']);
// print_r($info);
if(!$info)
{
// print_r($upload->getError());exit;
return 'error';
}else{
return $info['savepath'].$info['savename'];
}
}
/**
* 多文件上传
* @param array
* @return string
*/
function multi_upload2($param,$type=0){
$upload = new \Think\Upload();
$upload->maxSize = 102097152; //字节 1KB=1024字节 默认为200M
$upload->exts = array('jpg', 'gif', 'png', 'jpeg','mp3', 'wav', 'wma', 'ogg','ape','acc','flv','mp4','rmvb','avi','mpeg','ra','ram','mov','wmv');
$upload->savePath = $param['savePath']; //保存路径 相对路径
$upload->subName = $param['subName']; //子目录
$upload->saveName = array('uniqid',$param['saveName']); //保存名称 (uniqid有重复的可能)
$upload->saveExt = $param['saveExt']; //保存后缀
$upload->replace = true; //存在同名的文件 覆盖
// 上传文件
$info = $upload->upload($param['files']); //显示上传文件,参数为空会有异常
if(!$info) {
// 上传错误提示错误信息
return 'error';
}else{
// 上传成功 获取上传文件信息
foreach($info as $file){
$returPath[]=$file['savepath'].$file['savename'];
}
return $returPath;
}
}