public function dz_upload() { //上传多张缩略图 上传2张缩略图
if (isset($_FILES['ori_img'])){
$upload = new /Think/UploadFile();// 实例化上传类
$upload->maxSize = 3000000 ;// 设置附件上传大小 C('UPLOAD_SIZE');
//$upload->savePath = './Public/Uploads/' . $path; // 设置附件上传目录
$upload->savePath = './Public/Uploads/' . 'thumb/'; // 设置附件上传目录
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
$upload->saveRule = 'time';
$upload->uploadReplace = true; //是否存在同名文件是否覆盖
$upload->thumb = true; //是否对上传文件进行缩略图处理
$upload->thumbMaxWidth = '100,300'; //缩略图处理宽度
$upload->thumbMaxHeight = '50,150'; //缩略图处理高度
//$upload->thumbPrefix = $prefix; //缩略图前缀
$upload->thumbPrefix = 'm_,s_'; //生产2张缩略图
//$upload->thumbPath = './Public/Uploads/' . $path . date('Ymd', time()) . '/'; //缩略图保存路径
$upload->thumbPath = './Public/Uploads/' . 'thumb/' . date('Ymd', time()) . '/'; //缩略图保存路径
//$upload->thumbRemoveOrigin = true; //上传图片后删除原图片
$upload->thumbRemoveOrigin = false; //上传图片后删除原图片
$upload->autoSub = true; //是否使用子目录保存图片
$upload->subType = 'date'; //子目录保存规则
$upload->dateFormat = 'Ymd'; //子目录保存规则为date时时间格式
if (!$upload->upload()) {// 上传错误提示错误信息
echo json_encode(array('msg' => $this->error($upload->getErrorMsg()), 'status' => 0));
} else {// 上传成功 获取上传文件信息
$info = $upload->getUploadFileInfo();
$picname = $info[0]['savename'];
$picname = explode('/', $picname);
//$picname = $picname[0] . '/' . $prefix . $picname[1];
$picname = $picname[0] . '/' . '_hz' . $picname[1];
print_r($picname);
echo json_encode(array('status' => 1, 'msg' => $picname));
}
}
}
$k=A("Index"); // 调用控制器Index 的koo方法 重点(lish)
$slt=$k->dz_upload();
这里要注意thinkphp3.2.2并没有UploadFile,UploadImage 类,需要从扩展包里提取出来再自己加入,把他们放到ThinkPHP/Library/Think目录下.