Downloading files from Google Cloud Storage using the PHP API

Downloading files was something else I was barely able to piece together. I found an outdated version, but the SDK had changed enough that it wasn’t operable.

If you’re doing this in a class or method and just want to pass $gcs, then you can get the client with using $gcs->getClient().



2 thoughts on “Downloading files from Google Cloud Storage using the PHP API”

  1. I’ve tried to use your script to download a .jpg file directly from my Google Cloud Storage bucket, but the script does nothing. When I just display the $data->getResponseBody() then I get the file content but it doesn’t download it :/

    Please help


    Leo Reply:

    What you’re seeing is normal. That’s why I’m writing it out to a file in the script above.

    file_put_contents($filename, $data->getResponseBody());


Leave a Reply

Your email address will not be published. Required fields are marked *