时间:2021-07-01 10:21:17 帮助过:17人阅读
public function uploadify(){
if(!empty($_FILES)){
$config =array(
'maxSize' => 1024000,// 附件大小
'savePath'=> "attachment/picture/uploadify/",//附件保存路径
'saveName'=>array('uniqid',''),//附件保存名称
'exts'=>array('jpg','jpeg','png','gif','rar','zip'),//附件类型
'autoSub'=>true,//开启子目录保存
'subName'=>array('date','Ymd')//子目录命名规则
);
$upload=new \Think\Upload($config);
$files_upload=$upload->upload();
if($files_upload){
foreach($files_upload as $file){
// $info= $files_upload['Filedate']['savepath'].$files_upload['Filedata']['savename'];
// 上传后文件名
$savename=$file['savename'];
// 上传前文件名
$name=$file['name'];
// 上传文件类型
$type=$file['ext'];
// 上传文件大小 k
$size=$file['size'];
// 上传目录
$path=$file['savepath'].$file['subname'].$file['savename'];
$attachment=D('picture_attachment');
$date['creattime']=date('Y-m-d H:i:s',time());
$date['pictureurl']=$path;
$date['oldname']=$name;
$date['newname']=$savename;
$date['picturesize']=$size;
$date['picturetype']=$type;
$date['pictureid'] =$this->guid();// token guid
if( $attachment->create($date)){
$attachment->add();
session('guid',$date['pictureid']);
/* 返回给前台JS调用*/
echo $path ;
}
else{
unlink($path.$type);
session("FilesInFo",null);
}
}
;
}else{
/*返回报错信息*/
$info=$this->error($upload->getError(),U('picture/add'),30);
echo $info;
}
}
else{
echo '上传文件为空';
}
// end
}