适用对象:开放应用
接口路由:/basic/upload-file
请求方式:POST
参数 | 类型 | 是否必填 | 最大长度 | 描述 | 示例 |
type | string | 是 | 20 | 上传文件类型 | image |
remote | string | 是 | 远端文件地址 remote和file必填一项,都填时取remote字段 | https://www.rrsc.cn/Public/static/index/img/v5/v5_logo.png | |
file | file | 是 | 本地文件 remote和file必填一项,都填时取remote字段 |
值 | 描述 |
image | 图片 |
video | 视频 |
audio | 音频 |
type: 'image', remote: 'https://www.rrsc.cn/Public/static/index/img/v5/v5_logo.png'
$url = "http://open.v5.getpkg.cn/addons/renren_shop/public/index.php?r=client/apps/openApi/basic/upload-file&shop-id=9"; // 初始化 $ch = curl_init($url); // 复制临时文件 $newPath = APP_PUBLIC_TMP_PATH.'/'.$_FILES["file"]["name"]; copy($_FILES["file"]["tmp_name"], $newPath); // 创建 CURLFile 对象 $file = new CURLFile(($newPath)); // 设置文件类型 $file->setMimeType($_FILES["file"]['type']); $data = array( 'file' => $file, 'type' => 'image', // 其它必传参数 // ... ); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // 执行 $output = curl_exec($ch);
参数 | 类型 | 是否必填 | 最大长度 | 描述 | 示例 |
path | string | 是 | 文件保存路径 | image/0/2021/01/d67c393759fbdf0b817dc88e0c6ec647.png |
{ "error": 0, "path": "image/0/2021/01/d0c5a603f5a8d1cb445e5a66f4064978.png" }
错误码 | 错误描述 | 解决方案 |
555001 | 上传文件错误: 不支持的附件类型 不能上传空文件 最大支持上传xxKB的文件 禁止上传此类型文件 | 根据提示修改参数传值 |