Problems with object storages (S3, Google Cloud) as PHP stream wrappers
-
The plugin has some issues when using PHP Stream Wrappers backed by S3 or Google Cloud Storage, failing with “gs://bucket-name/wp-content/uploads/2017/12 is not writable”.
The issue reside in the fact that object storage are key/values stores with no notion of directories. A directory in this context is rather a convention, in general a key ending with ‘/’. PHP’s
dirname
returns the path without the trailing ‘/’.From what I can tell the fix is rather trivial, in
lib/class-wp-smush.php
,$dir_name
indo_smushit
function must be wrapped in atrailingslashit
. This does not affect Linux/Windows/MacOS becausedir
anddir/
are equivalent.Here’s the patch as well:
--- a/wp-smushit/lib/class-wp-smush.php 2017-10-03 20:04:20.000000000 +0300 +++ b/wp-smushit/lib/class-wp-smush.php 2017-12-07 16:49:49.000000000 +0200 @@ -191,7 +191,7 @@ */ function do_smushit( $file_path = '' ) { $errors = new WP_Error(); - $dir_name = dirname( $file_path ); + $dir_name = trailingslashit( dirname( $file_path ) ); //Check if file exists and the directory is writable if ( empty( $file_path ) ) {
- The topic ‘Problems with object storages (S3, Google Cloud) as PHP stream wrappers’ is closed to new replies.