function store($mode = '', $params = array()) { if ($mode == 'avatar') { delete_avatar($params['user_id'], $params['avatar_ext_id']); $file_path = get_avatar_path($params['user_id'], $this->file_ext_id); return $this->_move($file_path); } else { if ($mode == 'attach') { $file_path = get_attach_path($params['topic_id']); return $this->_move($file_path); } else { trigger_error("Invalid upload mode: {$mode}", E_USER_ERROR); } } }
/** * 上传图片--用于异步上传 * @author huqinlou * @version 2015年6月15日 下午5:00:35 * @Modify witner;2015年9月28日19:43:27 */ public function upload_image() { $path = I('get.path'); $path = './Uploads/' . $path . '/' . date('Y-m') . '/' . time() . rand(10000, 99999) . '.jpg'; if (!is_dir(dirname($path))) { mkdir(dirname($path), 0777, true); } $img = file_get_contents('php://input', 'r'); file_put_contents($path, $img); if (is_file($path)) { $path = trim($path, '.'); $this->ajaxReturn(array('status' => 0, 'name' => $path, 'url' => get_attach_path($path))); } else { $this->ajaxReturn(array('status' => 1, 'msg' => '上传失败')); } }