Jump to content

Pictures in php


OriginalSunny

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.
Link to comment
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
Link to comment
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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.