$cfile, 'type' => 'document' ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'token: test_token_for_upload_test', // 注意:不要设置 Content-Type,让curl自动设置为 multipart/form-data ]); echo "🚀 发送上传请求...\n"; $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); echo "HTTP状态码: $httpCode\n"; if ($error) { echo "CURL错误: $error\n"; } echo "响应内容:\n"; echo $response . "\n\n"; // 解析响应 $responseData = json_decode($response, true); if ($responseData) { if ($responseData['code'] == 1) { echo "✅ 上传成功!\n"; echo "文件URL: " . $responseData['data']['url'] . "\n"; echo "文件名: " . $responseData['data']['name'] . "\n"; echo "扩展名: " . $responseData['data']['ext'] . "\n"; } else { echo "❌ 上传失败: " . $responseData['msg'] . "\n"; } } else { echo "❌ 响应解析失败\n"; } // 清理测试文件 unlink($testFile); echo "\n🗑️ 测试文件已清理\n"; echo "\n📋 调试建议:\n"; echo "1. 检查前端是否使用了正确的参数名 'file'\n"; echo "2. 检查请求是否为 multipart/form-data 格式\n"; echo "3. 检查文件大小是否超过限制\n"; echo "4. 检查服务器错误日志\n"; echo "5. 检查腾讯云COS配置和权限\n"; ?>