处理中,请稍候...
本服务提供 API 接口,方便外部用户集成调用。
api.php
POST
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| submit | string | 是 | 提交标识,任意值均可 |
| image | file | 是 | 要处理的图片文件 |
返回JSON格式结果:
{"success": true, "image_url": "处理后的图片URL"}
{"success": false, "error": "错误信息"}
curl -X POST "http://localhost:8000/api.php" \ -F "submit=1" \ -F "image=@/path/to/your/image.jpg"
<?php
// 注意事项:
// 1. 请将 $imagePath 替换为实际的图片路径
// 2. 确保图片路径在服务器的 open_basedir 允许范围内
// 3. 例如:在服务器上应使用类似 '/www/wwwroot/qingxi.dewu.bar/images/test.jpg' 的路径
// 示例路径 - 请根据实际情况修改
$imagePath = '/www/wwwroot/qingxi.dewu.bar/images/test.jpg';
// 检查文件是否存在
if (!file_exists($imagePath)) {
die('错误:图片文件不存在');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:8000/api.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$postFields = [
'submit' => '1',
'image' => new CURLFile($imagePath)
];
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$response = curl_exec($ch);
curl_close($ch);
// 处理响应(重定向)
?>