wc上传图片:以上传头像为例

1.找到views/default/account/settings/profile.tpl.htm中

init_avatar_uploader($('#avatar_uploader'), $('#avatar_uploading_status'), $("#avatar_src"));//找到上传的三个控件

2.找到../static/js/functions.js文件中使用了jquery中的AjaxUpload方法

function init_img_uploader(upload_url, upload_name, upload_element, upload_status_elememt, perview_element)
{
return new AjaxUpload(upload_element, {
action: upload_url,//处理的图片上传的action,此处应该为:../app/account/ajax.php中的avatar_upload_action()
name: upload_name,
responseType: 'json',//数据格式为json onSubmit: function (file, ext) {//提交时做的验证以及页面变化
if (!new RegExp('(png|jpe|jpg|jpeg|gif)$', 'i').test(ext))
{
alert('上传失败: 只支持 jpg、gif、png 格式的图片文件'); return false;
} this.disable(); if (upload_status_elememt)
{
upload_status_elememt.show();
}
}, onComplete: function (file, response) {//数据从服务器返回时,做的处理
this.enable(); if (upload_status_elememt)
{
upload_status_elememt.hide();
} if (response.errno == -1)
{
alert(response.errno);
}
else
{
if (typeof(perview_element.attr('src')) != 'undefined')
{
perview_element.attr('src', response.rsm.preview + '?' + Math.floor(Math.random() * 10000));
}
else
{
perview_element.css('background-image', 'url(' + response.rsm.preview + '?' + Math.floor(Math.random() * 10000) + ')');
}
}
}
});
}

3.服务端的处理主要涉及到两个类../app/account/ajax.php与upload.php

function avatar_upload_action()
{
AWS_APP::upload()->initialize(array(
'allowed_types' => 'jpg,jpeg,png,gif',
'upload_path' => get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($this->user_id, '', 1),
'is_image' => TRUE,
'max_size' => get_setting('upload_avatar_size_limit'),
'file_name' => $this->model('account')->get_avatar($this->user_id, '', 2),
'encrypt_name' => FALSE
))->do_upload('user_avatar');if (AWS_APP::upload()->get_error())
{
switch (AWS_APP::upload()->get_error())
{
default:
H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('错误代码') . ': ' . AWS_APP::upload()->get_error()));
break; case 'upload_invalid_filetype':
H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('文件类型无效')));
break; case 'upload_invalid_filesize':
H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('文件尺寸过大, 最大允许尺寸为 %s KB', get_setting('upload_size_limit'))));
break;
}
} if (! $upload_data = AWS_APP::upload()->data())
{
H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('上传失败, 请与管理员联系')));
} if ($upload_data['is_image'] == 1)
{
foreach(AWS_APP::config()->get('image')->avatar_thumbnail AS $key => $val)
{
$thumb_file[$key] = $upload_data['file_path'] . $this->model('account')->get_avatar($this->user_id, $key, 2); AWS_APP::image()->initialize(array(
'quality' => 90,
'source_image' => $upload_data['full_path'],
'new_image' => $thumb_file[$key],
'width' => $val['w'],
'height' => $val['h']
))->resize();
}
} $update_data['avatar_file'] = $this->model('account')->get_avatar($this->user_id, null, 1) . basename($thumb_file['min']); // 更新主表
$this->model('account')->update_users_fields($update_data, $this->user_id); if (!$this->model('integral')->fetch_log($this->user_id, 'UPLOAD_AVATAR'))
{
$this->model('integral')->process($this->user_id, 'UPLOAD_AVATAR', round((get_setting('integral_system_config_profile') * 0.2)), '上传头像');
} H::ajax_json_output(AWS_APP::RSM( array(
'preview' => get_setting('upload_url') . '/avatar/' . $this->model('account')->get_avatar($this->user_id, null, 1) . basename($thumb_file['max'])
), 1, null));
}

4.大致流程完毕!

wc之上传图片的更多相关文章

  1. 博客使用BOS上传图片

    1.博客平台的选定 从大学开始做个人主页算起,最开始是使用html,CSSS写简单的页面,后面大学毕业之后接触到了WordPress,就开始用WordPress搭建网站.现在还维护着一个农村网站.ht ...

  2. nodejs利用ajax实现网页无刷新上传图片

    nodejs利用ajax实现网页无刷新上传图片 标签(空格分隔): nodejs 通常情况下上传图片是要通过提交form表单来实现的,但是这又不可避免的产生了网页转. 利用ajax技术和FormDat ...

  3. -Android -线程池 批量上传图片 -附php接收代码

    (出处:http://www.cnblogs.com/linguanh/) 目录: 1,前序 2,类特点 3,用法 4,java代码 5,php代码 1,前序 还是源于重构,看着之前为赶时间写着的碎片 ...

  4. iOS 原生HTTP POST请求上传图片

    今天项目里做一个上传图片等个人信息的时候,使用了第三方AFNetworking - (AFHTTPRequestOperation *)POST:(NSString *)URLString param ...

  5. 大朋展翅 html5上传图片(三)一解决部分手机拍相册批量上传图片转向问题

    在经过前面的改进之后本来以为已经没有问题了,但经过我们神通广大的测试的测试,发现相册中的图片在上传时也会发生转向问题.既然前面都解决了拍照转向的问题,那么相册中图片的上传也容易解决.修改一下需要旋转图 ...

  6. html5上传图片(一)一跨域上传

    最近开发一个上传图片的模块,传图片的接口不支持跨域上传,并且只支持单张上传,而我们的产品要求要实现多张上传.我搞了一个代理页面,先将图片传到代理页面,然后再通过代理页面传到上传图片接口.虽然这种方式经 ...

  7. h5上传图片及预览

    第一次做图片上传,记录一些问题. 1,图片的base64编码就是可以将一副图片数据编码成一串字符串,使用该字符串代替图像地址.而网页上的每一个图片,都是需要消耗一个http请求下载而来的,使用base ...

  8. .NET WebAPI 实现图片上传(包括附带参数上传图片)

    博主的项目,客户端是APP,考虑到以后也可能会应用到微信端.网站等,图片上传方法就需要兼容多端,并且以目前的设计,不允许非登录用户上传图片,就得在上传时解决附带参数上传图片的问题. 先来看看后台方法( ...

  9. java 上传图片

    1.导入smartupload.jar包 ,添加uploadIMG.jsp,upfileIMG.jsp. 2.需要在项目下面建立一个保存文件的文件夹pic或者upload 3.在调用的地方调用子框架u ...

随机推荐

  1. Macro and SQL

    If you’ve developed anything in the supply chain area, you’ve most probably come across InventDimJoi ...

  2. 怎么清除file控件的文件路径

    还记得上次做一个文件上传,后来测试告诉我说,如果我要是不选择文件了呢?该怎么办?我说:简单啊,做一个取消按钮不就完事了吗!然后我就想一个file空间做一个取消是多么简单的事,用js处理可是想怎么样就怎 ...

  3. [LeetCode]题解(python):112 Path Sum

    题目来源 https://leetcode.com/problems/path-sum/ Given a binary tree and a sum, determine if the tree ha ...

  4. Intersecting Lines---poj1269(求两直线的位置关系)

    题目链接:http://poj.org/problem?id=1269 题意:给你两条直线上的任意不同的两点,然后求两条直线的位置关系,如果相交于一点输出该点坐标; #include<iostr ...

  5. c#中的linq二

    c#中的linq二   using System; using System.Collections.Generic; using System.Linq; using System.Text; us ...

  6. table_tricks_基于bootstrap

    <!DOCTYPE html><html><head> <title>Bootstrap 实例 - 基本表单</title> <lin ...

  7. IEnumerable和IQueryable的区别

    转自:http://www.cnblogs.com/fly_dragon/archive/2011/02/21/1959933.html IEnumerable接口 公开枚举器,该枚举器支持在指定类型 ...

  8. Linux下设置网卡静态ip

    Linux下设置网卡静态ip 如果是服务器版,没有图形界面只用用命令行修改配置文件 如果是客户端版本,可以用图形界面 配置的前提是要在root用户下才能重启网卡服务 图形界面: system-conf ...

  9. 30天,O2O速成攻略【8.15济南站】

    活动概况 时间:2015年08月15日13:30-16:30 地点:山东大学凤岐茶社(山东大学中心校区北门18号楼东连廊一层) 主办:APICloud.蚁巡 网址:www.apicloud.com 费 ...

  10. Unicode 编码概念

    Unicode 编码概念 Unicode 编码可能是我们日常开发中接触最多的字符编码方式之一,其它常见的中文编码方式还包括 GB2132-80 / GB13000 / GBK / GB18030 .在 ...