Jump to content

Archived

This topic is now archived and is closed to further replies.

OriginalSunny

Pictures in php

Recommended Posts

Hi,
i am trying to change the size of the pictures i want to display in php. The problem is that when i try and do it the picture simply dissapears. In html i used width=100 and height =100 as shown below and it worked:

[i] <a href="simfreeMot.php"> <img src="Motorolla Logo.bmp" width=100 height=100></a>[/i]

I am using the code below to show the pic in php:

[i]echo "<img src='{$products[$i]['phonepic']}'>";[/i]

This works however when i try and change the size using:

[i]echo "<img src='{$products[$i]['phonepic']} width=100 height=100'>";[/i]

It comes up with no picture(as if there is a broken link to the picture. There is a blank page produced when i try:

[i]echo "<img src='{$products[$i]['phonepic'] width=100 height=100}'>";[/i]

If you know how to do this properly please let me know.
Thanks.

Share this post


Link to post
Share on other sites
You almost had it with this code
[code]<?php echo "<img src='{$products[$i]['phonepic']} width=100 height=100'>"; ?>[/code]

Try this (you had the terminating single quote in the wrong place)
[code]<?php echo "<img src='{$products[$i]['phonepic']}' width=100 height=100>"; ?>[/code]
or
[code]<?php echo '<img src="' .  $products[$i]['phonepic'] . '" width=100 height=100>'; ?>[/code]
In the above snippet, I interchanged the single and double quotes and using the string concatenation operator to form the final string.

Ken

Share this post


Link to post
Share on other sites
Bear in mind altering the height and width values of an image will simply distort them and in teh vast majority of cases this makes them look very poor - unprofessional even!

You can grab the size of the image on upload, or better still resample and create an image of the correct dimensions....

check out the gdlibrary for such magical trickery

Share this post


Link to post
Share on other sites
[!--quoteo(post=352858:date=Mar 8 2006, 09:26 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 8 2006, 09:26 AM) [snapback]352858[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You almost had it with this code
[code]<?php echo "<img src='{$products[$i]['phonepic']} width=100 height=100'>"; ?>[/code]

Try this (you had the terminating single quote in the wrong place)
[code]<?php echo "<img src='{$products[$i]['phonepic']}' width=100 height=100>"; ?>[/code]
[/quote]

also, keep in mind that if you're going for validation, ALL your attribute values need to have quotes around them. so, putting quotes around the height and width as well is best practice:
[code]
<?php
echo "<img src='{$products[$i][phonepic]}' width='100' height='100'>";
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.