I have a folder in my sites/default/files directory filled with product jpg's gathered from an external server and back end stock take system.
The files look like this...
- Bread.jpg
- Bakery.jpg
- Cakes+and+Puddings.jpg
- Chocolate+Bars.jpg
- Chocolates+%26+Treats.jpg
- Christmas+Fruit+%26+Veg.jpg
I am using theme_image_style in a custom block template to print the images using an image style from Drupal 7's core image handler like so...
<?php
print theme_image_style(
array(
'style_name' => 'category_header',
'path' => 'product_group_images/' . $productcategoryurl . '.jpg',
'attributes' => array(
'class' => 'category-header-image'
),
'width' => NULL,
'height' => NULL,
)
);
?>
Where $productcategoryurl
is the image name inside the product_group_images folder.
This all works great where the image is only one word, like bread.jpg
or bakery.jpg
The trouble I am having is the "+" or "&" (%26) in the image names.
I have tried str_replace to swap the spaces in the product name with "+", but in the path, the "+" is always encoded, and the image is never saved in the new style.
So my path comes out like....
- /sites/default/files/product_group_images/Chocolate%2BBars.jpg
Instead of...
- /sites/default/files/product_group_images/Chocolate+Bars.jpg
And therefore, no image is created in the /sites/all/files/styles directory.
Is there a way using the "path" in the array to actually use the "+" as a space without encoding it?
I hope ive explained that well enough, its late!