/** * 上传图片 */ public function upload() { // printJson('http://pic.baidu.com/upload/web/images/201603/56f9e14d508141496.jpg'); $file = $_FILES['file']; if (empty($file)) { printJson(null, 1, "未上传文件.请重试"); } $suffix = pathinfo($file['name'], PATHINFO_EXTENSION); $suffix = strtolower($suffix); if (!in_array($suffix, array('jpg', 'png', 'bmp', 'gif', 'jpeg'))) { printJson(null, 1, "上传文件格式不被支持"); } $file = file_get_contents($file['tmp_name']); $url = "http://pic.baidu.com/task/task.php?opt=uploadPic"; $res = RequestClient::http($url, null, array('block' => 'actbao', 'pic' => base64_encode($file))); Logger::debug("上传comment结果返回" . $res, RequestClient::getError()); if (empty($res) || $res == '500') { printJson(null, 1, "上传失败,请重试"); } $res = json_decode($res, true); if (!isset($res['url'])) { printJson(null, 1, "上传失败.请重试"); } printJson($res['url']); }