仿新浪微博上传头像组件,用ajax效果更好
仿新浪微博头像上传,支持本地图片拖动裁剪并时时预览,调用本地摄像头拍照并支持拖动裁剪,支持自定义亮度,对比度,饱和度,支持头像放大缩小,左右旋转。可以自定义上传目录以及图片后缀。采用ajax返回头像上传途径已经上传状态。完美兼容火狐,IE浏览器。组件下载地址
http://www.gouguoyin.cn/php/29.htm,使用过程中有任何疑问请咨询QQ:245629560。
模板页代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript">
function uploadevent(status,picUrl,callbackdata){
var time = new Date().getTime();
var filename162 = picUrl+'_162.jpg';
var filename48 = picUrl+'_48.jpg';
var filename20 = picUrl+"_20.jpg";
window.location.href="__APP__/member/do_avatar_edit?url="+filename162;
}
</script>
</head>
<body>
<div class="main">
<!--一定要注意PARAM里面的路径-->
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
WIDTH="650" HEIGHT="450" id="myMovieName">
<PARAM NAME=movie VALUE="__PUBLIC__/flash/avatar.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<param name="flashvars" value="imgUrl=__PUBLIC__/flash/default.jpg&uploadUrl=__PUBLIC__/flash/upfile.php&uploadSrc=ture" />
<EMBED src="__PUBLIC__/flash/avatar.swf" quality=high bgcolor=#FFFFFF WIDTH="650" HEIGHT="450" wmode="transparent" flashVars="imgUrl=__PUBLIC__/flash/default.jpg&uploadUrl=__PUBLIC__/flash/upfile.php&uploadSrc=ture"
NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash" allowScriptAccess="always"
PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
</div>
</body>
</html>
控制器代码
<?php
// 会员模块
class MemberAction extends Action {
//头像修改页面
public function avatar_edit(){
//验证是否登录
$this->islogin();
//显示模板
$this->display();
}
//处理头像修改方法
public function do_avatar_edit(){
$avatar=ltrim($_GET['url'],'../../');
$user_id=session('user_id');
$user_info=M('User_info');
$data['user_avatar']=$avatar;
$result=$user_info->where("user_id=$user_id")->save($data);
if($result === FALSE){
$this->error('头像修改失败!');
}elseif($result === 0){
$this->error('头像未做修改!');
}else{
$this->success('头像修改成功!');
}
}
}