Skip to content

Instantly share code, notes, and snippets.

@9paradox
Created May 30, 2021 14:31
Show Gist options
  • Save 9paradox/c7661562478b31cedce2a41d1c26fc1f to your computer and use it in GitHub Desktop.
Save 9paradox/c7661562478b31cedce2a41d1c26fc1f to your computer and use it in GitHub Desktop.
ImageKit folder delete function
//https://docs.imagekit.io/api-reference/media-api/delete-folder
public function deleteFolder($folderPath)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.imagekit.io/v1/folder/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_POSTFIELDS => 'folderPath='.$folderPath,
CURLOPT_HTTPHEADER => array(
'Authorization: Basic ' . base64_encode('YOUR_PRIVATE_KEY' . ':'),
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
if ($response) {
$resData = json_decode($response);
if($resData->reason && $resData->reason != "FOLDER_NOT_FOUND")
return ["success" => false, "data" => $resData];
}
return ["success" => true];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment