Welcome Guest, Not a member yet? Register   Sign In
Add Variable to image_thumb function?
#1

[eluser]invision[/eluser]
Hi,

The following works beautifully:
Code:
echo image_thumb('www.test.com/uploads/test.jpg', 50, 90);

but this doesn't:

Code:
$posts[img] = "test.jpg";

echo image_thumb('www.test.com/uploads/".$posts[img]."', 50, 90);

Can someone explain what I'm doing wrong.

I'm convinced it's something simple.



Many thanks.
#2

[eluser]Unknown[/eluser]
Try $posts['img'] instead of $posts[img]
#3

[eluser]danmontgomery[/eluser]
You're using a constant as the array index, which I assume should be a string (unless you've defined the 'img' constant for some reason). Also, you're mixing single and double quotes in your concatenation. Single quoted strings are interpreted literally.

Code:
$posts['img'] = 'test.jpg';
echo image_thumb('http://www.test.com/uploads/'.$posts['img'], 50, 90);
#4

[eluser]invision[/eluser]
Code:
Parse error: syntax error, unexpected T_STRING in ...../public_news_id.php on line 5

Line 5 is:
Code:
echo image_thumb('www.test.com/uploads/".$posts['img']."', 50, 90);
#5

[eluser]invision[/eluser]
[quote author="noctrum" date="1277240004"]You're using a constant as the array index, which I assume should be a string (unless you've defined the 'img' constant for some reason). Also, you're mixing single and double quotes in your concatenation. Single quoted strings are interpreted literally.

Code:
$posts['img'] = 'test.jpg';
echo image_thumb('http://www.test.com/uploads/'.$posts['img'], 50, 90);
[/quote]

Thanks for the reply.

Unfortunately, that suggestion doesn't seem to work either.

Instead it makes my file name: 50_90.jpg ??

I definitely have a value in $posts['img'] as I've returned it before using the image_thumb function.


Thanks for your help so far folks.
#6

[eluser]danmontgomery[/eluser]
What is the image_thumb function?
#7

[eluser]invision[/eluser]
Hi,

Here's the function I used: http://jrtashjian.com/blog/image-thumbna...deigniter/


Thank you!
#8

[eluser]danmontgomery[/eluser]
That's what the function does:

Code:
function image_thumb($image_path, $height, $width)
{
    // Get the CodeIgniter super object
    $CI =& get_instance();

    // Path to image thumbnail
    $image_thumb = dirname($image_path) . '/' . $height . '_' . $width . '.jpg';
#9

[eluser]invision[/eluser]
Eeeek.

Why then should this display the correct image:

Code:
echo image_thumb('www.test.com/uploads/test.jpg', 50, 90);

Or am I missing something obvious?


Thanks for your help with this.
#10

[eluser]danmontgomery[/eluser]
No idea, probably because www.test.com/uploads/test.jpg is an invalid path. The image library only works with local paths.




Theme © iAndrew 2016 - Forum software by © MyBB