thinkphp表单多图上传
表单多图上传//图片上传$upload=new\Think\Upload();//实例化上传类$upload->maxSize=3145728;//上传大小$upload...
表单多图上传//图片上传
$upload = new \Think\Upload();//实例化上传类
$upload->maxSize = 3145728;//上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = './Uploads/'; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
// 开启子目录保存 并以日期(格式为Ymd)为子目录
$upload->autoSub = true;
$upload->subName = array('date','Ymd');
//$this->load->library('upload',$config);
$info = $upload->upload();
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功 获取上传文件信息
foreach($info as $file){
var_dump($file['savepath'].$file['savename']);
}
}
$data['photo1']=$info['photo1']['savename'];
$data['photo2']=$info['photo2']['savename'];
为什么不能分别获取到两张图片的存储名字,打印是
string(26) "20170517/591bc68281f45.png" string(26) "20170517/591bc682822ec.png"
前端表单是
<input type='file' name='photo1'>
<input type='file' name='photo2'> 展开
$upload = new \Think\Upload();//实例化上传类
$upload->maxSize = 3145728;//上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = './Uploads/'; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
// 开启子目录保存 并以日期(格式为Ymd)为子目录
$upload->autoSub = true;
$upload->subName = array('date','Ymd');
//$this->load->library('upload',$config);
$info = $upload->upload();
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功 获取上传文件信息
foreach($info as $file){
var_dump($file['savepath'].$file['savename']);
}
}
$data['photo1']=$info['photo1']['savename'];
$data['photo2']=$info['photo2']['savename'];
为什么不能分别获取到两张图片的存储名字,打印是
string(26) "20170517/591bc68281f45.png" string(26) "20170517/591bc682822ec.png"
前端表单是
<input type='file' name='photo1'>
<input type='file' name='photo2'> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询