Reputation: 153
I have this very strange problem:
If I use absolute url/paths as image sources within my HTML codes (localhost - WAMP) by using $_SERVER['DOCUMENT_ROOT']
all of my images are broken and I don't know why :(
PHP includes are absolutely fine with it, only my images are behaving strangely. The absolute image path itself (generated by $_SERVER['DOCUMENT_ROOT']
+ my path variables) is working fine outside of localhost.(I have tried to copy and paste the url into my browser bar and the image shows up as expected. But in my localhost environment all images are broken) .
Example screenshot of this problem
As you can see here, my Chrome element inspector on link hover shows completely different image paths than the actual path created by $_SERVER['DOCUMENT_ROOT']
, and this drives me crazy because whats in the HTML is the CORRECT path, not the other one.... Any ideas how to fix this ?
Thanks in advance!
here are my codes so far:
$sysvar_category_default_image="/design/category_images/category_default.jpg";
$path= $_SERVER['DOCUMENT_ROOT'] .$sysvar_category_default_image;
// $path is: C:/wamp64/www/design/category_images/category_default.jpg
$path= $_SERVER['HTTP_HOST'] .$sysvar_category_default_image;
// $path is: localhost/design/img/icons/default.png
Both path working correctly pasted in the browser bar (these are the correct, actual image paths ),but my WampServer messing them up somehow ( maybe it's a configuration issue but i'm really lost at this point)
Upvotes: 2
Views: 71
Reputation: 12365
You are using document root? That is a local path and not a URL. Don't do that!
Use $_SERVER['HTTP_HOST']
instead, or just ignore the domain and have absolute urls starting from /
.
Upvotes: 4