实现头像上传及剪切功能(cakephp+jquery)
送给stone的文章:
此功能的优点就不多说了,具体实现如下:
1、必备:PHP4以上,gd库,jquery,及下载安装jquery.imgareaselect.min.js
2、创建组件jq_imgcrop.php,放在app/controllers/components
如果文件无法下载,用浏览器打开,查看源代码复制到相应文件中。
下载
3、创建helper助手cropimage.php,放在app/views/helpers/
下载
4、在控制器中添加引用
var $helpers = array(..., 'Cropimage') ;
var $components = array(..., 'JqImgcrop');
5、创建视图,使可以上传头像。
function icon()
{
if (!empty($this->data)) {
$uploaded = $this->JqImgcrop->uploadImage($this->data['User']['user_icon'], '/icon/', 'ef_',$this->Auth->user('user_id'));
$this->set('uploaded',$uploaded);
//echo $data['User']['user_icon'];exit;
if (!isset($data['User']['user_icon'])||$data['User']['user_icon']==''){
$suffix = substr(strrchr($this->data['User']['user_icon']['name'], "."), 1);
$user_icon = 'ef_'.$this->Auth->user('user_id').'.'.$suffix;
$this->User->query("UPDATE users SET user_icon = '".$user_icon."' where user_id= ".$this->Auth->user('user_id')."");
}}
$data= $this->User->findByUserId($this->Auth->user('user_id'), array("user_icon"));
$this->set('user_icon',isset($data['User']['user_icon'])?$data['User']['user_icon']:"user.jpg");
}
6、上传后跳转到的控制器:
function crop()
{
if (!empty($this->data)) {
$this->JqImgcrop->cropImage(48, $this->data['User']['x1'], $this->data['User']['y1'], $this->data['User']['x2'], $this->data['User']['y2'], $this->data['User']['w'], $this->data['User']['h'], $this->data['User']['imagePath'], $this->data['User']['imagePath']) ;
}
$this->redirect('/users/setting');
}
参考:
http://www.zhuyinghao.com/?p=220
朱老师,什么时候推出cakephp与flex结合的课程啊?
暂时没有出flex的教程打算,你可以参考一些flex的书籍,flex与php结合并不是太好,需要借助中间件。
感谢豪哥的cake教程,希望再多出一些,越详细越好哦~~
多谢,豪哥的视频资料
朱老师的课程太棒了
感谢豪哥的cake教程,希望你能把phpnow于cakephp1.2结合在改详细一点。对于我们初学者来说。还是有些不能理解。再多出一些,越详细越好哦…
能问下朱老师多大了吗?
这个上传头像 功能,按照你的这个的话。怎么浏览呀。我是初学者。感觉怎么少了很多哦。
没有个demo么?
很久不做CAKE了,抱歉