thinkphp中怎么处理上传文件
1个回答
2016-11-18 · 知道合伙人软件行家
关注
展开全部
$n = $m->add();
if ($n){
$str = "添加成功";
}else {
$str = "添加失败";
}
$this->assign("str",$str);
$this->display("upload");
}
// 文件上传
protected function _upload() {
import("@.ORG.UploadFile");
$upload = new UploadFile();
//设置上传文件大小
$upload->maxSize = 3292200;
//设置上传文件类型
$upload->allowExts = explode(',', 'jpg,gif,png,jpeg,pjpeg,bmp,doc,rar,txt');
//设置附件上传目录
$upload->savePath = './Public/upload/';
//设置上传文件规则
$upload->saveRule = uniqid;
if (!$upload->upload()) {
//捕获上传异常
$this->error($upload->getErrorMsg());
} else {
//取得成功上传的文件信息
$uploadList = $upload->getUploadFileInfo();
//import("@.ORG.Image");
//给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
/*Image::water($uploadList[0]['savepath'].'m_'.$uploadList[0]['savename'], '/ThinkPHP_2.1_full_with_extend/Examples/File/Tpl/default/Public/Images/logo2.png'); */
return $uploadList[0]['savename'];
}
if ($n){
$str = "添加成功";
}else {
$str = "添加失败";
}
$this->assign("str",$str);
$this->display("upload");
}
// 文件上传
protected function _upload() {
import("@.ORG.UploadFile");
$upload = new UploadFile();
//设置上传文件大小
$upload->maxSize = 3292200;
//设置上传文件类型
$upload->allowExts = explode(',', 'jpg,gif,png,jpeg,pjpeg,bmp,doc,rar,txt');
//设置附件上传目录
$upload->savePath = './Public/upload/';
//设置上传文件规则
$upload->saveRule = uniqid;
if (!$upload->upload()) {
//捕获上传异常
$this->error($upload->getErrorMsg());
} else {
//取得成功上传的文件信息
$uploadList = $upload->getUploadFileInfo();
//import("@.ORG.Image");
//给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
/*Image::water($uploadList[0]['savepath'].'m_'.$uploadList[0]['savename'], '/ThinkPHP_2.1_full_with_extend/Examples/File/Tpl/default/Public/Images/logo2.png'); */
return $uploadList[0]['savename'];
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询