How can I delete an object from the Google Cloud Storage using PHP?
google-app-engine, php
Solution
From the delete_object example, you could try adding a function like this to your project:
function delete_object($bucketName, $objectName, $options = [])
{
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
$object->delete();
printf('Deleted gs://%s/%s' . PHP_EOL, $bucketName, $objectName);
}
Then to delete the actual file, you could use the function like this:
delete_object('sample-storage', 'myfolder/new_file2.jpg');
Problem
Can someone tell me how to delete an object from the Google Cloud Storage using PHP? I found how to add an object via ``` move_uploaded_file($gs_name, "gs://sample-storage/myfolder/new_file2.jpg"); ``` get the public URL via ``` $public_url = CloudStorageTools::getPublicUrl("gs://sample-storage/myfolder/new_file2.jpg", true); ``` By importing the following as well ``` require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php'; use google\appengine\api\cloud_storage\CloudStorageTools; ``` But how do you delete a file using PHP? Can someone please share the code in PHP that works? Even using JavaScript if PHP doesn't implicitly support it.