if (!empty($_FILES)) { //图片上传设置 $config = array( 'maxSize' => 3145728, 'rootPath' => './upload/', 'saveName' => array('uniqid',''), 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'autoSub' => false, 'subName' => array('date','Ymd'), ); $upload = new \Think\Upload($config);// 实例化上传类 $images = $upload->upload(); //判断是否有图 if($images){ $info=$images['Filedata']['savename']; //返回文件地址和名给JS作回调用 echo $info; } else{ $this->error($upload->getError());//获取失败信息 } } }