CakePHP: Define an image URL into a Variable
I'm trying to define a variable for an Image URL which is something like this:
http://MyWebSite.com/app/webroot/upload/foods/2/beef_wellington_thumb.jpg
The number 2 digit in the link is an $id and also represents the folder number. The image file name is originally beef_wellington.jpg
. But I have to display it using an additional underscore:_thumb
for each image file name due to an upload component (plugin) I'm using in Cake. So how should I go about in defining a variable for that: e.g.
$itemImageurl = "/app/webroot/upload/foods/".$id开发者_开发问答./$item['Food']['image'];
What about the _thumb
? could we place it somewhere in the line of code above?
UPDATE:
Assuming I have changed the upload plugin so I can also add my original image file name in my folder as this:
http://MyWebSite.com/app/webroot/upload/foods/2/beef_wellington.jpg
without needing _thumb
How to write the correct variable, I'm not sure about this:
$itemImageurl = "/app/webroot/upload/foods/".$id./$item['Food']['image'];
How about finding the last dot in $item['Food]['image] and replace it with "_thumb."?
e.g. (not tested):
$newName = basename("/app/webroot/upload/foods/".$id./$item['Food']['image'],".jpg");
$newName = newName."_thumb.jpg";
does it work?
精彩评论