本文整理汇总了PHP中think\Upload::getErrorMsg方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::getErrorMsg方法的具体用法?PHP Upload::getErrorMsg怎么用?PHP Upload::getErrorMsg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类think\Upload
的用法示例。
在下文中一共展示了Upload::getErrorMsg方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadImg
public function uploadImg()
{
$upload = new Upload(C('UPLOAD_CONFIG'));
// 实例化上传类
//头像目录地址
$path = './Avatar/';
if (!$upload->upload()) {
// 上传错误提示错误信息
$this->ajaxReturn(array('status' => 0, 'info' => $upload->getErrorMsg()));
} else {
// 上传成功 获取上传文件信息
$temp_size = getimagesize($path . 'temp.jpg');
if ($temp_size[0] < 150 || $temp_size[1] < 150) {
//判断宽和高是否符合头像要求
$this->ajaxReturn(array('status' => 0, 'info' => '图片宽或高不得小于100px!'));
}
$this->ajaxReturn(array('status' => 1, 'path' => __ROOT__ . '/Avatar/' . 'temp.jpg'));
}
}
示例2: do_edit
/**
* 处理修改
*/
public function do_edit()
{
C('TOKEN_ON', false);
// dump($_POST);
// exit;
$file = $_FILES;
$file = $file['advert_image'];
$file = $file['name'];
// dump($file);
// exit;
if (empty($file)) {
$m = D('Advert');
if (!$m->create()) {
$this->error($m->geterror());
}
$data['id'] = I('post.id');
$data['advert_nav'] = I('post.advert_nav');
$data['advert_name'] = I('post.advert_name');
$data['advert_remark'] = I('post.advert_remark');
$data['advert_url'] = I('post.advert_url');
$data['advert_sort'] = I('post.advert_sort');
$data['advert_show'] = I('post.advert_show');
$count = $m->save($data);
//修改表单用save函数
if ($count > 0) {
$this->success('修改成功!');
} else {
$this->error('修改失败!');
}
} else {
$id = I('post.id');
$m = M('Advert');
$arr = $m->find($id);
// dump($arr);
// exit;
if (!$arr['advert_image'] == null) {
//删除本地图片附件 unlink('图片url')
unlink('./Uploads' . $arr["advert_image"]);
}
$upload = new \Think\Upload();
// 实例化上传类
$upload->maxSize = 3145728;
// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');
// 设置附件上传类型
$upload->savePath = './Uploads/';
// 设置附件上传根目录
$upload->savePath = '/Images/';
// 网站主栏目图片 设置附件上传(子)目录
$upload->autoSub = true;
$upload->subName = array('date', 'Ymd');
$upload->saveName = array('uniqid', '');
//设置上传文件规则
$info = $upload->upload();
//设置需要生成缩略图,仅对图像文件有效
//$upload->thumb = true;
//设置需要生成缩略图的文件后缀
//$upload->thumbPrefix = 'm_,s_'; //生产2张缩略图
//设置缩略图最大宽度
//$upload->thumbMaxWidth = '400,100';
//设置缩略图最大高度
//$upload->thumbMaxHeight = '400,100';
//$upload->thumbRemoveOrigin = true;//删除原图
if (!$info) {
//捕获上传异常
$this->error($upload->getErrorMsg());
} else {
//取得成功上传的文件信息
//给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
//Image::water($uploadList[0]['savepath'] . 'm_' . $uploadList[0]['savename'], APP_PATH.'Tpl/Public/Images/logo.png');
//dump($uploadList[0]);
//exit;
foreach ($info as $file) {
$image = $file['savepath'] . $file['savename'];
$size = $file['size'];
}
}
// dump($size);
// exit;
$m = M('Advert');
$data['id'] = I('post.id');
$data['advert_nav'] = I('post.advert_nav');
$data['advert_name'] = I('post.advert_name');
$data['advert_remark'] = I('post.advert_remark');
$data['advert_url'] = I('post.advert_url');
$data['advert_show'] = I('post.advert_show');
$data['advert_sort'] = I('post.advert_sort');
//$date['advert_time']=time();
$data['advert_image'] = $image;
$data['advert_size'] = $size;
$count = $m->save($data);
//修改表单用save函数
// dump($count);
// exit;
if ($count > 0) {
$this->success('修改成功!');
} else {
//.........这里部分代码省略.........