Reputation: 247
I am facing some typical issue in loading image files in PHP. Image got successfully loaded but cannot get displayed properly.
I have declared a define value, then echoed it in an img
tag src
attribute :
define('image_site_url','localhost/projects/faantush/product_images/');
<img src="<?php echo image_site_url.$row['image1'] ?>" />
The image file is not found but it is there in product_images. Here are the pictures:
Upvotes: 1
Views: 396
Reputation: 3497
If your pictures are hosted on the same server than your website, you don't really need to use an absolute path. You could use a relative path and remove the domain name (localhost
in this case):
<img src="/projects/path/to/your/picture.jpg" />
You must use absolute paths when linking to another website, but you can also use absolute paths within your own website. This practice is generally frowned upon, though. Relative links make it easy to do things like change your domain name without having to go through all your HTML pages, hunting down links and changing the names. As an added bonus, they force you to keep your site structure neat and organized, which is always a good idea.
An interesting use case of not using absolute paths is, if you want to set your website to SSL/TLS
: you will have to change all the occurrences of http
to https
. Although it is not a big deal, this is generally not the kind of work you want to do.
See Relative path or url for html src and href attributes and the post from where this quote is taken.
Upvotes: 2
Reputation: 1146
In the HTML code: You are missing the: http://
before localhost
<img src="http://localhost/
...
Upvotes: 2