核桃说笔记2

php上传头像修改上传头像操作
function
editimg() { /*echo "<pre>"; print_r( $_FILES);die;*/ $navtitle = "修改个人头像"; if (isset ( $_FILES ["userimage"] )) { $uid = intval ( $this->uri->segment ( 3 ) ); $avatardir = "/data/avatar/"; $extname = extname ( $_FILES ["userimage"] ["name"] ); if (! isimage ( $extname )) $this->message ( "图片扩展名不正确!", 'user/editimg' ); $upload_tmp_file = FCPATH . 'data/tmp/user_avatar_' . $uid . '.' . $extname; $uid = abs ( $uid ); $uid = sprintf ( "%09d", $uid ); $dir1 = $avatardir . substr ( $uid, 0, 3 ); $dir2 = $dir1 . '/' . substr ( $uid, 3, 2 ); $dir3 = $dir2 . '/' . substr ( $uid, 5, 2 ); (! is_dir ( FCPATH . $dir1 )) && forcemkdir ( FCPATH . $dir1 ); (! is_dir ( FCPATH . $dir2 )) && forcemkdir ( FCPATH . $dir2 ); (! is_dir ( FCPATH . $dir3 )) && forcemkdir ( FCPATH . $dir3 ); $smallimg = $dir3 . "/small_" . $uid . '.' . $extname; if (move_uploaded_file ( $_FILES ["userimage"] ["tmp_name"], $upload_tmp_file )) { $avatar_dir = glob ( FCPATH . $dir3 . "/small_{$uid}.*" ); foreach ( $avatar_dir as $imgfile ) { if (strtolower ( $extname ) != extname ( $imgfile )) unlink ( $imgfile ); } image_resize ( $upload_tmp_file, FCPATH . $smallimg, 85, 85, 1 ); $this->message ( '修改头像成功', 'user' ); } } else { if ($this->setting ["ucenter_open"]) { $this->load->model ( 'ucenter_model' ); $imgstr = $this->ucenter_model->set_avatar ( $this->user ['uid'] ); } } include template ( "editimg" ); }

未完待续。。。。。。。。。

原文地址:https://www.cnblogs.com/yszr/p/10748577.html