API接口:https://imgdd.com/api/v1/upload
上传参数:
file => 图片
请求头:
Referer: https://imgdd.com/
<?php
// IMGDD图床接口
// By: Linuors
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$apiUrl = 'https://imgdd.com/api/v1/upload';
$file = $_FILES['file'];
if ($file['error'] !== UPLOAD_ERR_OK) {
http_response_code(400);
echo json_encode(['error' => 'File upload error.']);
exit;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, 1);
$cFile = new CURLFile($file['tmp_name'], $file['type'], $file['name']);
$postData = ['image' => $cFile];
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Referer: https://imgdd.com/'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
if (isset($responseData['url'])) {
echo $responseData['url'];
} else {
echo $response;
}
} else {
http_response_code(400);
echo json_encode(['error' => 'No file uploaded.']);
}
?>