• Welcome to the Chevereto User Community!

    Here, users from all over the world come together to learn, share, and collaborate on everything related to Chevereto. It's a place to exchange ideas, ask questions, and help improve the software.

    Please keep in mind:

    • This community is user-driven. Always be polite and respectful to others.
    • Support development by purchasing a Chevereto license, which also gives you priority support.
    • Go further by joining the Community Subscription for even faster response times and to help sustain this space

where is delete function located?

TriHoang

Chevereto Member
I want to add a request to CloudFlare API to delete the image from cache.
Please tell me where is the delete function located and what variables are available in it?
Thank you!
 
Actually that function is hard-coded in the system. You should worry about that function for V3 and above.
 
As I see that you're not too busy now, can you point this out for me?
I just need to make a quick file_get_contents to CloudFlare API to purge the file.
Thank you!
 
For V3:

Delete an image
PHP:
CHV\Image::delete(<id>);

Delete multiple images
PHP:
CHV\Image::deleteMultiple([id1, id2, idn...,]);

Delete an abum
PHP:
CHV\Album::delete(<id>);

Delete multiple abums
PHP:
CHV\Album::deleteMultiple([id1, id2, idn...,]);

Delete user
PHP:
CHV\User::delete(<id>);

NOTE: All the IDs are the real ones (integers) not the public ids.

Cheers.
 
Thanks Rodofo, I am finally did it.

To anyone who wonder how to purge images from CloudFlare when deleting it, here is my solution.
+ root>app>lib>classes>class.image.php
find (and please check that it have to be in delete function)
PHP:
$target = $image_db[$file_delete];

and add this code under it (edit it to fit your configuration)
PHP:
$cdn = str_replace("/path/to/chevereto_base/", "http://domain-or-subdomain-using.cdn/", $target);
file_get_contents('https://www.cloudflare.com/api_json.html?tkn=your-cloud-flare-api-key&email=cloudflare-acount-email&z=cloudflare-zone-domain&a=zone_file_purge&url='.$cdn);

For example, with my server configuration at estimg.com (I am using cloudflare to cache and serve files only on b.estimg.com), it would be
PHP:
$cloud = str_replace("/var/www/", "http://b.estimg.com/", $target);
file_get_contents('https://www.cloudflare.com/api_json.html?tkn=296522af4fd40d9d0f4fab951c442aejustkd&email=mahemail@gmail.com&z=estimg.com&a=zone_file_purge&url='.$cloud);

To be clear, this will not immediately delete images from Cloudflare, it will send a request to Cloudflare to purge the file. It would take up to a few minutes for the image to be deleted. Otherwise, if we don't send a request, the image would stay on their CDN for hours or days.
 
Back
Top