Heim >Backend-Entwicklung >PHP-Tutorial > thinkphp 无刷新下传头像 有dialog弹出层对话框效果 有水印功能
thinkphp 无刷新上传头像 有dialog弹出层对话框效果 有水印功能
运用的是jquery中的插件,温馨提示请下载好js。
<script><br> <span style="white-space:pre">// increase the default animation speed to exaggerate the effect<br> <span style="white-space:pre">var $j = jQuery.noConflict();<br> <span style="white-space:pre"> var old_width='';<br> <span style="white-space:pre">$j(function() {<br> <span style="white-space:pre">//配置dialog弹出框<br> <span style="white-space:pre">$j( "#uploader" ).dialog({<br> <span style="white-space:pre">autoOpen: false,<br> <span style="white-space:pre">dialogClass: "my-dialog",<br> //<span style="white-space:pre"> show: "blind",<br> //<span style="white-space:pre"> hide: "explode",<br> <span style="white-space:pre">width: 750,<br> <span style="white-space:pre">minWidth: 400,<br> <span style="white-space:pre">position: [420,185], // 弹出时,出现的地方<br> <span style="white-space:pre">draggable:true<br> <span style="white-space:pre">});<br> </script>
//打开dialog
$j( ".up_photo" ).click(function() {
$j( "#uploader" ).dialog( "open" );
return false;
});
$j( ".cl_photo" ).click(function() {
$j( "#uploader" ).dialog( "close" );
return false;
});
$j( "#next" ).click(function() {
$j.ajaxFileUpload ({
url:'../../Home/photoupload', //文件上传的到这来
secureuri:false,
fileElementId:'pic', //要和input file那个id名字相同
dataType: 'json',
success: function (data, status) {
if(data){
if(data==10101){
alert("您已经上传5张照片了");
window.top.location.reload();
}else{
$j('#up_content').css('display','none');
$j('#ima').css('display','');
$j('.tailor').attr('src',data);
$j('#uploader_step').text("2");
$j('#ima_hidden').attr("value",data);
tail_photo();
$j.post('../../Home/ima_hei',{url_image:data},function (data){
var old_width=data;
$j("#old_width0").attr("value",old_width);
});
}
}
},
error: function (data, status, e){
alert(e);
}
})
});
})
//下面的是php代码
public function photoupload(){
session_start();
$user = M('User_photo');
$con0 = $user->query("select COUNT(id) as CON from cup_user_photos where
user_id='".session('user_id')."'");
if($con0[0]['CON']>=5){
echo "10101";
}else{
import("ORG.Net.UploadFile");
$upload = new UploadFile();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->saveRule = time();
$upload->thumb = true;
$upload->thumbMaxWidth = "1024";
$upload->thumbMaxHeight = "768";
$upload->thumbRemoveOrigin = true;
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload_file="public/image/".date('Ymd')."/".session('username')."/";
$upload_dir=create_folders($upload_file);
$upload->savePath = $upload_dir;// 设置附件上传目录
//给图片加水印
import('ORG.Util.Image');
$Image = new Image();
$uploadfile='/'.$info[0]['savepath'].'thumb_'.$info[0]['savename'];
$Image->water($uploadfile,'/public/image/1336954430057.png');
if(!$upload->upload()) {// 上传错误提示错误信息
$this->error($upload->getErrorMsg());
}else{// 上传成功 获取上传文件信息
$info =$upload->getUploadFileInfo();
//给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
//给图片加水印
$uploadfile='/'.$info[0]['savepath'].'thumb_'.$info[0]['savename'];
echo $uploadfile;
}
}
}
//如果想要上传后并有剪切功能请看下个帖子