jeremydricard wrote:I'm trying to use it strictly to learn it. So using the html is more effecient in this case? I just want to know whatever is the more up to date way of doing things. So it's best I pull up the user image from the folder with img_src ? do i have to send out headers?
thanks, all appreciated. learning this <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> on the run.
The functions like imagecreatefrom... are used when you have to generate a NEW image that doesn't exist in the format you need. They are resource intensive functions and should never be used if the image already exists in a format you can use. If you have an image in either .jpg, .gif, or .png format, they are universally recognized by all browsers and only need to be referenced as the
src attribute of an
<img... html element.
No, you do not need to explicitly send headers in this circumstance. Ordinarily you would send the normal html lines, such as <!DOCTYPE HTML> (that's for HTML5, earlier DocTypes are much lengthier), <html>, <head>, <title>, </title>, </head>, <body>, and later, the </body> and </html>. That can be done either by using either print() or echo(), if you need to insert a lot of dynamic content, or more commonly just put those lines
outside the <?php ... ?> block.
Indeed, if you are just trying to display an image on a web page and you know the path to the image on the server, there is no reason to use PHP at all. You only need to use HTML:[text]<img src='user_images/image.jpg' alt='My Image' />[/text]
PHP would be used only when you can't predict what image, for example, will be requested. In that case you would probably have a script that presents a form for the user to indicate what image they want to see, or a list of choices, each of which is an anchor element, like[text]<a href='test.php?img="image8.jpg'>Number 8</a>[/text]
Then this script would use either $_POST (data from a form) or $_GET (data from a URL) to obtain the image name. In that case, your script might look more like this:
Code: Select all
<!DOCTYPE HTML>
<html>
<head>
<title>Image Test</title>
</head>
<body>
<?php
$filename = $_GET['img'];
$path = 'user_images/';
echo "echo <img src='$path.$filename' alt='Your image' />";
?>
</body>
</html>