API接口:https://i.111666.best/image
上传参数:
file => 图片
需要携带请求头Auth-Token,值任意,用于删除图片
<?php
// 16图床接口
// By: Linuors
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$apiUrl = 'https://i.111666.best/image';
$file = $_FILES['file'];
if ($file['error'] !== UPLOAD_ERR_OK) {
http_response_code(400);
echo json_encode(['error' => 'File upload error.']);
exit;
}
$randomToken = bin2hex(random_bytes(8));
$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 = ['file' => $cFile];
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Auth-Token: $randomToken"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
if ($responseData && isset($responseData['src'])) {
$imageUrl = $responseData['src'];
echo 'https://i.111666.best' . $imageUrl;
} else {
echo $response;
}
} else {
http_response_code(400);
echo json_encode(['error' => 'No file uploaded.']);
}
?>
https://i.111666.best/image/AvSfrJ3DuJtlx8u5Jnlrsv.jpg