google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

PHP fopen is supported with the modes `X` and `XB`

Open adiux opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe. We are trying to save a temporary file (email) on Google Cloud Storage via the Swiftmailer library. This leads to an Error "failed to open stream".

Apparently, this is expected since the Swiftmailer library uses fopen with the XB flag. This mode is not supported: https://github.com/googleapis/google-cloud-php-storage/blob/1382afef595c2ced1c5e39ead91d903e8ebc8e22/src/StreamWrapper.php#L27 https://github.com/googleapis/google-cloud-php/blob/2823f6f35b7913dded8094fe2f018f2c58d9476d/Storage/src/StreamWrapper.php#L27

I tested it manually with the W flag. This works as expected.

Describe the solution you'd like Files are written to the bucket on Google Cloud Storage with the X or XB flag. The modes X and XB are supported.

Additional context I tested with this code:

        // ok: writes file to bucket
        $file = @fopen('gs://BUCKET/temp/test-wb'.time().'.txt', 'wb');
        $successwriteWb = fwrite($file, "Hello World. WB Testing!");
        fclose($file);

        // throws exception: fwrite(false, 'Hello World. XB...')
        $file = @fopen('gs://BUCKET/temp/test-xb'.time().'.txt', 'xb');
        $successwriteXb = fwrite($file, "Hello World. XB Testing!");
        fclose($file);

adiux avatar Feb 18 '22 07:02 adiux