此功能的优点就不多说了,具体实现如下: 1、必备:PHP4以上,gd库,jquery,及下载安装<a href="http://odyniec.net/projects/imgareaselect/">jquery.imgareaselect.min.js</a> 2、创建组件jq_imgcrop.php,放在app/controllers/components <a href="http://www.zhuyinghao.com/wp-content/uploads/2009/03/jq_imgcrop.php">下载</a> 3、创建helper助手cropimage.php,放在app/views/helpers/ <a href="http://www.zhuyinghao.com/wp-content/uploads/2009/03/cropimage.php">下载</a> 4、在控制器中 <script src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js" type="text/javascript"></script> <script src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js" type="text/javascript"></script> 添加引用 <code> var $helpers = array(..., 'Cropimage') ; var $components = array(..., 'JqImgcrop'); </code> 5、创建视图,使可以上传头像。 <code>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"); }</code> 6、上传后跳转到的控制器: <code> 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'); }</code> 参考:http://www.zhuyinghao.com/?p=220
实现头像上传及剪切功能(cakephp+jquery)
最新推荐文章于 2020-04-03 14:04:23 发布