此代码适用于清除缓存中的所有文件。
示例:
$authKey = "MyKEY";
$authEmail = "myEMAIL";
$zoneId = "MYZONEID";
$endpoint = "purge_cache";
$data = [
"purge_everything" => true
];
$url = "https://api.cloudflare.com/client/v4/zones/{$zoneId}/{$endpoint}";
$opts = ['http' => [
'method' => 'DELETE',
'header' => [
"Content-Type: application/json",
"X-Auth-Key: {$authKey}",
"X-Auth-Email: {$authEmail}",
],
'content' => json_encode($data),
]];
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
但是我需要通过URL清除单个文件如何通过PHP实现?
在api页面上,我找到了这个链接:https://api.cloudflare.com/#zone-purge-individual-files-by-url
但我现在不知道如何通过php制作它?
答案 0 :(得分:3)
您需要传递一个包含文件的数组 - 如API Docs
中所述在您的示例中,类似于
$data = '{"files":[
"http://www.example.com/css/styles1.css",
"http://www.example.com/css/styles2.css",
"http://www.example.com/css/styles3.css"
]}';