0

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'];

1
  • If you're trying to access this file (/app/webroot/upload/foods/$id/$item['Food']['image']) via the URI, it will be example.com/upload/foods/etc). app/webroot are only for accessing via filesystem. I also recommend you use cake's built-in constants (rather than app/webroot). Jan 27, 2011 at 19:13

1 Answer 1

1

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?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.