public function upload1() { if (IS_POST) { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = 'mytest/'; // 设置附件上传(子)目录 // 上传文件 $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 // $this->ajaxReturn($upload->getError(),"AJAX_UPLOAD"); $this->ajaxReturn(sp_ajax_return(array(), $upload->getError(), 0), "AJAX_UPLOAD"); } else { // 上传成功 // $this->ajaxReturn('ssss',"AJAX_UPLOAD"); // $this->ajaxReturn(sp_ajax_return(array("file"=>array(1,2,3)),"上传成功!",1),"AJAX_UPLOAD"); echo json_return($info, 'ooo', 1); // echo 'okkkk'; } } else { $this->display(); } }
function post() { /* if($_SESSION['_verify_']['verify']!=I("post.verify")){ $this->error("验证码错误!"); } */ if (IS_POST) { $post_table = sp_authcode($_POST['post_table']); $_POST['post_table'] = $post_table; $url = parse_url(urldecode($_POST['url'])); $query = empty($url['query']) ? "" : "?{$url['query']}"; $url = "{$url['scheme']}://{$url['host']}{$url['path']}{$query}"; $_POST['url'] = sp_get_relative_url($url); if (isset($_SESSION["user"])) { //用户已登陆,且是本站会员 $uid = $_SESSION["user"]['id']; $_POST['uid'] = $uid; $users_model = M('Users'); $user = $users_model->field("user_login,user_email,user_nicename")->where("id={$uid}")->find(); $username = $user['user_login']; $user_nicename = $user['user_nicename']; $email = $user['user_email']; $_POST['full_name'] = empty($user_nicename) ? $username : $user_nicename; $_POST['email'] = $email; } if (C("COMMENT_NEED_CHECK")) { $_POST['status'] = 0; //评论审核功能开启 } else { $_POST['status'] = 1; } if ($this->comments_model->create()) { $this->check_last_action(intval(C("COMMENT_TIME_INTERVAL"))); $result = $this->comments_model->add(); if ($result !== false) { //评论计数 $post_table = ucwords(str_replace("_", " ", $post_table)); $post_table = str_replace(" ", "", $post_table); $post_table_model = M($post_table); $pk = $post_table_model->getPk(); $post_table_model->create(array("comment_count" => array("exp", "comment_count+1"))); $post_table_model->where(array($pk => intval($_POST['post_id'])))->save(); $post_table_model->create(array("last_comment" => time())); $post_table_model->where(array($pk => intval($_POST['post_id'])))->save(); $this->ajaxReturn(sp_ajax_return(array("id" => $result), "评论成功!", 1)); } else { $this->error("评论失败!"); } } else { $this->error($this->comments_model->getError()); } } }
function avatar_upload() { $config = array('FILE_UPLOAD_TYPE' => sp_is_sae() ? "Sae" : 'Local', 'rootPath' => './' . C("UPLOADPATH"), 'savePath' => './avatar/', 'maxSize' => 512000, 'saveName' => array('uniqid', ''), 'exts' => array('jpg', 'png', 'jpeg'), 'autoSub' => false); $upload = new \Think\Upload($config); // $info = $upload->upload(); //开始上传 if ($info) { //上传成功 //写入附件数据库信息 $first = array_shift($info); $file = $first['savename']; $_SESSION['avatar'] = $file; $this->ajaxReturn(sp_ajax_return(array("file" => $file), "上传成功!", 1), "AJAX_UPLOAD"); } else { //上传失败,返回错误 $this->ajaxReturn(sp_ajax_return(array(), $upload->getError(), 0), "AJAX_UPLOAD"); } }